Pentland_web
Pentland_web

Reputation: 11

301 Redirect adding incorrect extra segments to a url

I need to 301 redirect one segment of a url to a new version of it.

My aim is redirect

www.domain.co.uk/farm/whatever/

to

www.domain.co.uk/farm_cottages/whatever/

The rule I am using to do this is:

RedirectMatch 301 ^/farm/ /farm_cottages/

However for some reason it partially works but appends ?/farm/ after farm_cottages/ in the final url ie.

www.domain.co.uk/farm_cottages/?/farm/whatever/

Here is my entire rewrite rule set as I believe one of the rewrite rules could be interfering with the redirect rule.

#redirect /farm/ to /farm_cottages/
RedirectMatch 301 ^/farm/  /farm_cottages/

<IfModule mod_rewrite.c>
RewriteEngine on

# no WWW to WWW
RewriteCond %{HTTP_HOST} !^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,L]

# Force trailing slash on URLs
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.co.uk/$1/ [L,R=301]

#Remove index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.+) $1 [R=301,L]

</IfModule>

The site is built in Expressionengine and so the segments of url do not represent actual folders - I don't think this should matter though.

Any ideas would be much appreciated! Thanks

Upvotes: 0

Views: 1097

Answers (1)

Pentland_web
Pentland_web

Reputation: 11

Ok I solved this in the end with the following - I hope it might help someone in the future:

RewriteRule ^farm/(.*)$ /farm_cottages/$1 [QSA,R=301,L]

Upvotes: 1

Related Questions