Mobile app version of vmapp.org
Login or Join
Barnes591

: Mod rewrite rule question/help 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/

@Barnes591

Posted in: #Apache #Htaccess #Redirects

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

RewriteCond %{HTTP_HOST} !^www.mysite.co.uk$ [NC]
RewriteRule ^(.*)$ www.mysite.co.uk/ [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 - 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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

2 Comments

Sorted by latest first Latest Oldest Best

 

@Goswami781

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_HOST}/welcome-to-my-website/ [R=301,L]

10% popularity Vote Up Vote Down


 

@Karen161

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)$ www.mysite.co.uk/welcome-to-my-website/ [L,R=301]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme