简体   繁体   中英

redirect old dynamic urls to seo friendly urls through htaccess

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.

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]

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