问题
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