jhodgson4
jhodgson4

Reputation: 1656

Redirecting domain with htaccess

I'm moving my site from the .com version to the .co.uk. The only issue is there are some admin facilities that I want to keep on the .com site. I've set up my .htaccess to redirect everything but requested files and directories that exist which works fine, except for the root of the site, I can't get that to redirect.

Here is my htaccess...

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ http://www.site.co.uk/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.site.co.uk/$1 [R=301,L]

Upvotes: 1

Views: 25

Answers (1)

anubhava
anubhava

Reputation: 785886

You can use this code:

RewriteEngine On
RewriteBase /

RewriteRule ^(index\.php)?$ http://www.site.co.uk/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.site.co.uk/$1 [R=301,L]

This regex ^(index\.php)?$ will match index.php OR empty string (landing page).

Upvotes: 1

Related Questions