Wednesday, April 6, 2011

htaccess for redirection

htaccess for redirection. so when user enter http://www.mydomain.com or http://mydomain.com it will redirect to http://www.mydomain.com/mysubfolder.
Below is the .htaccess code to be put in the public_html directory.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomain\.com\/mysubfolder" [R=301,L]

htaccess to display subfolder as the domain name

inside the public_html directory, we want to use the subfolder for example named 'mysubfolder' but in the url shown as http://www.mydomain.com or http://mydomain.com instead of http://www.mydomain.com/mysubfolder.

Below is the .htaccess code to be put in the public_html directory.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteCond %{REQUEST_URI} !^/mysubfolder/
RewriteRule ^(.*)$ mysubfolder/$1 [L]