开发者

mod_rewrite 301 Redirect: from old to new dynamic url

I am trying to get a mod_rewrite working correctly.

Here is the code:

RewriteCond %{QUERY_STRING} ^main_page=product_info&pr开发者_如何学运维oducts_id=301$ 
RewriteRule ^index\.php$          
/blog/shop/index.php?route=product/product&product_id=301? [R=301,L]

It works, but in the end of the new URL %3f is added. Can somebody help me to get it work?


Put no-escape flag NE at the end:

RewriteRule ^index\.php$          
/blog/shop/index.php?route=product/product&product_id=301? [R=301,L,NE]


%3f is the question mark at the end of your statement. Take that out and you should be good.

RewriteCond %{QUERY_STRING} ^main_page=product_info&products_id=301$ 
RewriteRule ^index\.php$          
/blog/shop/index.php?route=product/product&product_id=301 [R=301,L]


%3f is the "?" you have at the end of your "Target URL" - just URL escaped. Is this really supposed to be there?


The %3f is the ? at the end of your replacement in percent-encoding. Just drop the ? at the end:

RewriteCond %{QUERY_STRING} ^main_page=product_info&products_id=301$ 
RewriteRule ^index\.php$ /blog/shop/index.php?route=product/product&product_id=301 [R=301,L]

You would only use a ? at the end to indicate an empty query so that the requested query does not get appended to the new URL if it does not contain a query.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜