包含问号的htaccess url重写网址

问题描述:

我在重定向一些网址时遇到了问题,下面有很多不同的猫品种的网址。任何人都可以帮助解决此问题。包含问号的htaccess url重写网址

范例网址重定向:

http://www.exampledomain.co.uk/cats/database.nsf/catsforsale!openform?Breed=Persian 

我希望它重定向到以下网址。我的PHP脚本,然后应该做一些更复杂的重定向,使整齐的网址:

http://www.exampledomain.co.uk/display_pets.php?pettype=Cats&petbreed=Persian 

我试过下面的重写,但它不工作,它只是不重定向可言,我认为它可能有事可做与? :

RewriteRule ^/cats/database.nsf/catsforsale!openform?Breed=(.*)$ display_pets.php?pettype=Cats&petbreed=$1 [L] 
+0

重写规则只有URL的路径组件相匹配。如果你想检查查询字符串的内容,你需要使用RewriteCond。 – CBroe

RewriteRule通常不会查询查询字符串。

您需要在重写中使用QSA标志。它结合了查询字符串并将其附加到目标url。

你可以尝试以下方法:

RewriteRule ^(.*)$ display_pets.php?url=$1 [L] 

这将整个源URL传递到目标网址的网址参数。它还会将源url的查询字符串附加到目标url。

另一种选择是匹配RewriteCond中的查询字符串。

RewriteCond %{QUERY_STRING} url=(.*) 
RewriteRule ^/cats/database.nsf/catsforsale!openform$ display_pets.php?pettype=Cats&petbreed=%1 [L] 

参见以下链接:

RewriteRule FlagsManipulating the Query String