developer__c
developer__c

Reputation: 636

.htaccess - condition on condition?

I have the following .htaccess file setup to rediect all my .co.uk site traffic to the sites new .com domain name.

# Redirect all requests NOT made under www.domain.com
RewriteCond %{REQUEST_URI} !/admin
#RewriteCond %{HTTP_HOST} !^www\.domain-name\.com [NC]

#RewriteRule ^(.*)$ http://www.domain-name\.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.domain-name\.com

RewriteRule (.*) http://www.domain-name.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}       !-d

RewriteCond %{REQUEST_FILENAME}       !-f

RewriteRule ^(.+) index.php?seo_path=$1&%{QUERY_STRING} [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/

RewriteRule ^index\.php$ http://www.domain-name.com/ [R=301,L]

ErrorDocument 404 /page-not-found.php

However I want to redirect .co.uk/blog to the new .com/blog however, at the moment, all that happens is when you visit .co.uk/blog it redirects to the .com homepage. - I believe this is because of;

   RewriteRule ^(.+) index.php?seo_path=$1&%{QUERY_STRING} [L]

How would I add a condition to overrule this if the URL ends /blog?

Upvotes: 0

Views: 97

Answers (1)

anubhava
anubhava

Reputation: 784898

Actually your very first rule is making .co.uk to .com that needs to skip subsequent rule for /blog.

Have your rules like this:

# if request_uri doesn't start with /blog or /admin
RewriteCond %{REQUEST_URI} !^/(admin|blog) [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?domain-name\.com$ [NC]
RewriteRule ^ http://www.domain-name.com%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteRule ^(.+)$ /index.php?seo_path=$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php[\s?] [NC]
RewriteRule ^ http://www.domain-name.com/ [R=301,L]

ErrorDocument 404 /page-not-found.php

Upvotes: 1

Related Questions