osakagreg
osakagreg

Reputation: 577

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]

Upvotes: 2

Views: 400

Answers (1)

user2493235
user2493235

Reputation:

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.

Upvotes: 2

Related Questions