[英]htaccess 301 redirect regex
I am trying to 301 redirect this format or url 我正在尝试301重定向此格式或网址
mydomain.com/texas/map-of-texas/
to 至
mydomain.com/texas/
I have a lot of urls of states and cities with this pattern so I need a regex rule but I can't seem to get the regex syntax right. 我有很多使用这种模式的州和城市网址,因此我需要一个正则表达式规则,但似乎无法正确使用正则表达式语法。
I have used this and similar. 我用过这个和类似的。 What am I doing wrong?
我究竟做错了什么?
RewriteRule ^/map-of(.+) mydomain.com /$1 [R=301,L]
The ^
matches the start of the path portion of the url, but in your example "map-of" is not at the beginning of the url. ^
与网址的路径部分的开头匹配,但是在您的示例中,“ map-of”不在网址的开头。 Furthermore, mod_rewrite paths do not start with a /
, but directly with the url path. 此外,mod_rewrite路径不是以
/
开头,而是直接以url路径开头。
A mod_rewrite rule that rewrites all urls containing "map-of-" looks like this: 重写所有包含“ map-of-”的URL的mod_rewrite规则如下所示:
RewriteRule (^|/)map-of-(.+?)(/|$) /$2 [R=301,L]
The ?
?
means that the match is not "greedy". 表示匹配不是“贪婪”。
The rewrite rule redirects the following type of urls 重写规则重定向以下类型的网址
mydomain.com/texas/map-of-texas/
mydomain.com/texas/map-of-texas/123
mydomain.com/map-of-texas
to 至
mydomain.com/texas
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.