正则表达式htaccess

时间:2014-02-13 09:47:22

标签: regex .htaccess redirect

我需要一个简单的正则表达式来匹配asp页面并将它们重定向到另一个页面。

例如

/showdetails.asp?id=1334

/page-redirect.php?page=showdetails&id=1334

这是我到目前为止似乎没有用的东西

RedirectMatch 301 ^/(.*)\.asp?id=(.*)$ /page-redirect.php?page=$1&id=$2

其中

RedirectMatch 301 ^/(.*)\.asp$ /page-redirect.php?page=$1

确实有用。


没关系自己解决了,需要逃避?

    RedirectMatch 301 ^/(.*)\.asp\?id=(.*)$ /page-redirect.php?page=$1&id=$2

3 个答案:

答案 0 :(得分:0)

此致

301 ^/(.*)\.asp?id=(.*)$ /page-redirect.php?page=$1&id=$2

正确

301 ^/(.*)\.asp\?id=(.*)$ /page-redirect.php?page=$1&id=$2

考虑

301 ^/([^/]+)\.asp\?id=(\d+)$ /page-redirect.php?page=$1&id=$2

答案 1 :(得分:0)

可能会逃离?中的asp?id

答案 2 :(得分:0)

使用RedirectMatch 指令无法匹配查询字符串,因此所提出的解决方案都不起作用。

您需要使用基于mod_rewrite的规则..

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=([^&]+)$ [NC]
RewriteRule ^([^.]+)\.asp$ /page-redirect.php?page=$1&id=%1 [L,NC,R=301]
相关问题