Mike
Mike

Reputation: 53

Why doesn't this htaccess RewriteRule "stick"?

I'm trying to redirect http://vacation.website.com/category/spa-vacations/ to http://website.com/vacations/spa-vacations/

RewriteEngine On
RewriteRule ^category/(.*)$ $1
RewriteCond %{HTTP_HOST} ^vacation\.website\.com [NC]
RewriteRule ^(.*) https://website.com/vacations/$1 [L,R=301]

Screencap from htaccess tester

With this htaccess, the first rule seems to be applied and removes "category" from the URL - then it's like it never happened and I'm left with http://website.com/vacations/category/spa-vacations/

Why doesn't the first change to the URL stick and is it possible to make it do so?

Upvotes: 0

Views: 24

Answers (1)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

To redirect

http://vacation.website.com/category/spa-vacations/

to

http://website.com/vacations/spa-vacations/

Try this :

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?vacation\.website\.com [NC]
RewriteRule ^category/(.*)$ https://website.com/vacations/$1 [L,R=301]

Note: clear browser cache then test.

Upvotes: 1

Related Questions