Htaccess redirect URL with parameters

I have hundreds of links like this:

http://www.domain.com/index.php?tag=value

I want to redirect all links to

http://www.domain.com/value/

Example:

Link1 http://www.domain.com/index.php?tag=LW1fdX49tR redirect to:http://www.domain.com/LW1fdX49tR/

Link2 http://www.domain.com/index.php?tag=A3kh0QLIrc redirect to:http://www.domain.com/A3kh0QLIrc/

Link3 http://www.domain.com/index.php?tag=vXwNR4U9qY redirect to:http://www.domain.com/vXwNR4U9qY/

etc.

How can i do this? Thank!

+4
source share
1 answer

, , , , URL- . . THE_REQUEST , URL , . .

#External redirect with THE_REQUEST trick; change R to R=301 when everything works correctly
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?tag=(.*)\ HTTP
RewriteRule ^ /%2? [R,L]

#Internal rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?tag=$1 [L]
+4

Source: https://habr.com/ru/post/1532892/


All Articles