简体   繁体   English

通过htaccess将旧的动态url重定向到seo友好的url

[英]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 我已经建立了动态​​网址(rr.php?rrid = 5),现在我要切换到seo友好的网址(rr / 5 / name /),我已经在工作了

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. 我遇到的问题是实现301重定向,以告知搜索引擎该网址已更改,而不会导致重定向循环。 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=# 另外,我有数百个rrid =#,并且我想要一种类似于上述规则的301,其中/ name /部分取决于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. 我知道有一种方法可以将&rewrite添加到上述规则中,但是我无法弄清楚如何编写301重定向,而不必逐一进行。

You need to have an additional rule for 301 handling. 您需要具有处理301的附加规则。 Place this code in your DOCUMENT_ROOT/.htaccess file: 将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM