1

Im using mod_rewrite to direct all non-www requests to the www. url using the following code

RewriteEngine On
Options +FollowSymLinks


# non-www to www resolve
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]

however i recently changed the index page from .html to .php and have several external links still pointing to the index.html page.

simply adding a 301 redirect results in a loop due to the above rule

#1 Permanent URL redirect
Redirect 301 /index.html http://www.website.co.uk/

How can i adapt this code to maintain a non-www redirect and also redirect index.html requests to index.php or www.website.co.uk/

anubhava
  • 761,203
  • 64
  • 569
  • 643
AndyKing
  • 139
  • 2
  • 15
  • possible duplicate of [Generic htaccess redirect www to non-www](http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – opalenzuela Jan 20 '14 at 13:35

1 Answers1

1

Keep your rule like this:

DirectoryIndex index.php

RewriteEngine On
Options +FollowSymLinks

# non-www to www resolve
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]

# index.html to /
RewriteCond %{THE_REQUEST} \s/index\.html [NC]
RewriteRule ^ / [L,R=301]
anubhava
  • 761,203
  • 64
  • 569
  • 643