Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
add comment

migrated from stackoverflow.com Jun 9 '11 at 12:37

This question came from our site for professional and enthusiast programmers.

2 Answers

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]
share|improve this answer
    
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? –  Goonyan Harir Jun 8 '11 at 13:16
    
After spending most of last night trying different combinations, I finally found the answer. Thanks @Floern for your assistance. –  Goonyan Harir Jun 9 '11 at 10:46
add comment
up vote 0 down vote accepted

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]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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