2014-02-13 83 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,也許吧。