Set redirect in .htaccess for all the urls with a suffix

一曲冷凌霜 提交于 2020-01-06 03:45:29

问题


I have the urls like:

example.com/vm-search/parentcategory-cityname/childcategory-cityname

They are indexed by search engines. I decided to remove the cityname suffix from all the parentcategories and now I need to set redirect from all the old urls to new ones before the search engines will index them. The citynames are the same for all the urls and the new urls will be like:

example.com/vm-search/parentcategory/childcategory-cityname

I haven't try anything with htaccess yet. What rule should I add to the file?


回答1:


You can use this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^(vm-search/.+?)/results,\d+-\d+$ /$1 [L,NC]

RewriteRule ^(vm-search/(?:[^/-]+/)*[^/-]+)-[^/]+/(.*)$ /$1/$2 [L,NC,R=302]


来源:https://stackoverflow.com/questions/30298289/set-redirect-in-htaccess-for-all-the-urls-with-a-suffix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!