301 redirection code
-
27-06-2021 - |
Domanda
I have created 301 redirection code for my website. Following is my code to all my categories to redirect to new url
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^testsite.com/categories/city/$1 [nc]
rewriterule ^(.*)$ http://www.testsite.com/$1 [r=301,nc]
I want to redirect http://www.testsite.com/categories/city/pune to http://www.testsite.com/Pune
Let me know my code is correct or not?
Thanks
Soluzione
It's not correct. The %{HTTP_HOST}
is only the host that's provided in the Host:
header of the request. It's not going to include any path info. You could separate that condition into 2 things:
RewriteCond %{HTTP_HOST} ^testsite.com$ [NC]
RewriteRule ^/?categories/city/(.*)$ /$1 [R=301,L,NC]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow