简体   繁体   中英

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/

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:

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

No need for the RewriteBase either. And you had doubled up the slash before the category which you're already capturing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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