Reputation: 105
I have looked through the other posted questions and I cant seem to find an answer that pertains to my specific situation. I have already established dynamic urls (rr.php?rrid=5) and I am switching over to seo friendly urls (rr/5/name/) I have that part working
RewriteRule ^rr/([0-9]+)/([a-z\+\-]+)/?$ /rr.php?rrid=$1 [L]
The problem I am having is implementing a 301 redirect to tell the search engines that the urls have changed without causing a redirect loop. Also, I have hundreds of rrid=# and I would like a way to do the 301 similar to the above rule where the /name/ portion is different depending on the rrid=#
I know there is a way to add &rewrite to the above rule but I cant figure out how to write the 301 redirect without having to go through and do each one individually.
Upvotes: 1
Views: 463
Reputation: 784958
You need to have an additional rule for 301 handling. Place this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+rr\.php\?rrrid=([0-9]+) [NC]
RewriteRule ^ /rr/%1? [R=302,L]
RewriteRule ^rr/([0-9]+)/?$ /rr.php?rrid=$1 [L,QSA]
RewriteRule ^rr/([0-9]+)/([a-z+-]+)/?$ /rr.php?rrid=$1 [L,QSA]
Upvotes: 1