简体   繁体   English

htaccess 301 重定向多个网址

[英]htaccess 301 redirect for multiple urls

I have many urls such as:我有很多网址,例如:

mydomain.com/location/illinois/

mydomain.com/location/wisconsin/green-bay/

mydomain.com/location/new-york/

I have removed the word location and replaced it with: /blog/category/我删除了位置一词并将其替换为:/blog/category/

so those urls should now be:所以这些网址现在应该是:

mydomain.com/blog/category/illinois/

mydomain.com/blog/category/wisconsin/green-bay/

mydomain.com/blog/category/new-york/

I am trying to get this done with one rewrite rule.我正在尝试通过一个重写规则来完成这项工作。 But the one I created is not working.但是我创建的那个不起作用。 Can you tell me what is wrong with it?你能告诉我它有什么问题吗?

Here is what I tried:这是我尝试过的:

RewriteEngine On

RewriteBase /

RewriteRule ^/location(/.*|)$ /blog/category/$1 [L,NC,R=301]

Nice try, you just need to drop the opening slash which is not included in .htaccess matches:不错的尝试,您只需要删除不包含在 .htaccess 匹配项中的斜杠:

RewriteEngine On
RewriteRule ^location(/.*|)$ /blog/category$1 [L,NC,R=301]

No need for the RewriteBase either.也不需要 RewriteBase。 And you had doubled up the slash before the category which you're already capturing.并且您在您已经捕获的类别之前将斜杠加倍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM