重定向设置在.htaccess中所有带有后缀的网址 [英] Set redirect in .htaccess for all the urls with a suffix
本文介绍了重定向设置在.htaccess中所有带有后缀的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网址,如:
example.com/vm-search/parentcategory-cityname/childcategory-cityname
它们被搜索引擎收录。我决定从所有parentcategories去除城市名后缀,现在我需要从所有旧的URL到新的搜索引擎将索引之前重定向设置。该citynames是相同的所有URL和新URL,将是这样的:
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
我还没有尝试与htaccess的任何事情。我应该添加到文件有什么规则?
I haven't try anything with htaccess yet. What rule should I add to the file?
推荐答案
您可以在 DOCUMENT_ROOT /的.htaccess
文件中使用这个规则:
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]
这篇关于重定向设置在.htaccess中所有带有后缀的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文