htaccess url重写包含问号的网址

时间:2017-06-13 11:32:57

标签: php apache .htaccess redirect mod-rewrite

我无法重定向某些网址,如下所示,有许多不同品种的网址。任何人都可以帮助解决这个问题。

要重定向的网址示例:

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]

1 个答案:

答案 0 :(得分:0)

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

您需要将QSA标志与Rewrite一起使用。它结合了查询字符串并将其附加到目标URL。

您可以尝试以下操作:

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

这会将整个源url传递给目标url的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

相关问题