简体   繁体   中英

htaccess dynamic URLs redirect

Hello i want to redirect some dynamic URL to some static urls eg

  • /folder/index.php?rid=321

to

  • http ://example.com/folder/some-name-321.htm

And

  • /folder/index.php?rid=324

to

  • http ://example.com/folder/some-other-name-324.htm

I tried

Redirect 301 /folder/index.php?rid=321 http ://example.com/folder/some-name-321.htm
Redirect 301 /folder/index.php?rid=324 http ://example.com/folder/some-other-324.htm

But not working. How i should redirect these URLs Also, where should i place my htaccess file. This should be in /folder/.htaccess or i should place rules in main htaccess file present in root of site.

Kind Regards

You can never match against a Query string using Redirect (mod-alias) directive. To manipule query strings you need to use mod-rewrite the following rule in /root.htaccess

RewriteEngine on


RewriteCond %{QUERY_STRING} ^rid=(.+)$
RewriteRule ^index\.php$ http://example.com/folder/some-name-%1.htm? [NC,L,R]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM