.htaccess在url和301重定向上插入一个单词

时间:2013-12-12 10:34:19

标签: regex .htaccess redirect

我们的网址结构如下:

  

www.domain.com/browse-technology-videos-1-date.html

     

www.domain.com/browse-technology-videos-1-rating.html

     

www.domain.com/browse-technology-videos-1-views.html

     

www.domain.com/browse-technology-videos-1-title.html

新结构将是:

  

www.domain.com/browse-science-and-technology-videos-1-date.html

     

www.domain.com/browse-science-and-technology-videos-1-rating.html

     

www.domain.com/browse-science-and-technology-videos-1-views.html

     

www.domain.com/browse-science-and-technology-videos-1-title.html

所有这些都是生成的网址所以重点是添加-science-并且网址中只有技术并将旧结构重定向到新结构

我们如何实现这一目标?

非常感谢你提前

1 个答案:

答案 0 :(得分:1)

试试这个:

#if www.domain.com is important for you, remove the # of next line
#RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^browse-technology-(.*)$ http://%{HTTP_HOST}/browse-science-and-technology-$1 [R=301,L]

这是另一个案例:

RewriteCond %{REQUEST_URI} !^/browse-art-and-cinema
RewriteRule ^browse-art-(.*)$ http://%{HTTP_HOST}/browse-art-and-cinema-$1 [R=301,L]