I have the following ruleset in my .htaccess file which basically rewrites my php pages and makes them appear as subfolders, so for example, http://www.mysite.co.uk/about-me/ points to http://www.mysite.co.uk/about.php:

Options +FollowSymLinks
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

RewriteRule ^index.php$ /welcome-to-my-website/ [L,R=301,NC]
ReWriteRule ^welcome-to-my-website/$ index.php [NC,L]
ReWriteRule ^about-me/$ about.php [NC,L]
ReWriteRule ^my-portfolio/$ portfolio.php [NC,L]
ReWriteRule ^contact-us/$ contact.php [NC,L]

What I want to do is to automatically forward/redirect the root - http://www.mysite.co.uk/ - and the index.php page straight to /welcome-to-my-website/ via htaccess so that there is no duplicate content. Any idea how one may achieve this?

2 Answers 2


I guess, following 3 RewriteConds are not necessary, you can remove them:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

To redirect the root and index.php to /welcome-to-my-website/ you can use this:

RewriteRule ^(|index\.php)$ http://www.mysite.co.uk/welcome-to-my-website/ [L,R=301]
  • I'm either doing something wrong, or it is not working correctly. I took out the three rewriteconds and added in the rewrite rule you so kindly provided, but Firefox fails saying 'The page isn't redirecting properly'. Is there a specific place in the ruleset this needs to go - I tried moving it above and below the ReWriteRule ^welcome-to-my-website/$ index.php [NC,L] rule? Commented Jun 8, 2011 at 13:16
  • After spending most of last night trying different combinations, I finally found the answer. Thanks @Floern for your assistance. Commented Jun 9, 2011 at 10:46

The following code redirects a user if index.php or root of a website is typed into the browser. If anyone can refine the following any further, please let us know. I really hope this helps someone save a lot of time and their sanity:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(|index\.php)\ HTTP/
RewriteRule ^(|index\.php)$ http://%{HTTP_HOST}/welcome-to-my-website/ [R=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.