I'm tryin' to replace old-style urls to the new one user-friendly only using .htaccess
e.g. domain.com/dir/?id=101 -> domain.com/dir/robots
It should be accessed from old links (?id=...)
by users or searchbots and redirected to the new one with 301 status code and of course it s开发者_StackOverflow社区hould be accessed from the new url.
my .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /dir/
RewriteRule ^robots/?$ ?id=101 [L]
RewriteCond %{QUERY_STRING} ^id=101$
RewriteRule ^$ robots? [R=301,L]
It returns redirection loop, obviously.
Unfortunately i can not modify CMS engine, so the only solution is to do this with .htaccess rules.
I've googled a lot but didn't found any working solution for this issue.
Any ideas?
Thanks!
SOLVED
Ok, a little bit of random magic and i found solution:
RewriteRule ^robots/?$ ?id=101 [L]
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteCond %{QUERY_STRING} ^id=101$
RewriteRule ^$ robots? [R=301,L]
Important: No space after !=200
in condition RewriteCond %{ENV:REDIRECT_STATUS}
. with space it doesnt work.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /dir/
RewriteRule ^robots/?$ ?id=101 [L]
RewriteCond %{QUERY_STRING} ^/id=101$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/dir/robots? [R=301,L]
精彩评论