开发者

Rewrite rule not trying to redirect

I have this 301 redirect rule for Apache:

RewriteEngine On

RewriteRule ^park.php?park_id=3       http://hiking.comehike.com/outdoors/parks/park.php?park_id=3 [R=301,L]

I am trying to get this url:

http://www.comehike.com/outdoors/parks/park.php?park_id=3

to redirect to this url:

http://hiking.comehike.com/outdoors/parks/park.php?park_id=3

But as I have it now, it isn't tr开发者_开发技巧ying to redirect. The .htaccess file with the rule is located in the /parks/ directory.

Is there anything I am doing wrong? Seems like this should be relatively straight forward.

Thanks!


It's the query string; you need to add a conditional to be able to pick up on it, something like:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^park_id=3$
RewriteRule ^park.php http://hiking.comehike.com/outdoors/parks/park.php?park_id=3 [R=301,L]

That works when I mung it into an .htaccess on my localhost anyway.

It might be better to eventually, since it's RegExp pattern matching to do something like:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^park_id=([0-9]+)$
RewriteRule ^park.php http://hiking.comehike.com/outdoors/parks/park.php?park_id=%1 [R=301,L]

Which will pick up the integer at the end of the address and pass it to the new address (it's actually easier if you don't have a query string in the original address of course).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜