2014-02-13 85 views
1

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

例如

/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 

回答

0

无法使用RedirectMatch指令匹配查询字符串,因此没有任何提议的解决方案将工作。

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

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^id=([^&]+)$ [NC] 
RewriteRule ^([^.]+)\.asp$ /page-redirect.php?page=$1&id=%1 [L,NC,R=301] 
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 
0

逃离?asp?id,也许吧。