Redirect index.php to root, and www to non www with rewrite_mod

17,758

Since I'm guessing index.php is what gets served when you go to your document root, you want to explicitly check that /index.php is what is being requested, and not part of the URI, which it will be once the URL-file mapping pipeline does its thing.

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

Then the www to non-www:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
Share:
17,758
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    someone knows how can i redirect in the .htaccess this rules bellow ?

    http://www.domain.com/index.php to http://domain.com
    

    and

    http://www.domain.com to http://domain.com 
    

    many tanks