Redirecting http://www.example.com/ to http://www.example.com/dir2/ Print

  • 0

This redirection will be done using Apache's mod_rewrite with the .htaccess file. You will need to create a .htaccess file under your domain's root directory, which is ~username/yourdomain.com/, if it doesn't exist. If it does, simply open the file and edit it. In the file, add the following lines: 

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !^/dir2/
RewriteRule ^(.*)$ /dir2/$1 [R] 


Change example.com with your domain, and dir2 with the directory name you want to redirect to. 

If you want the browser to retain the URL, that is to have the browser showing http://www.example.com/ instead of http://www.example.com/di2/, simply remove the [R] from the last line.

Was this answer helpful?

« Back