Wednesday, 13 March 2013

URL redirection using .htaccess


     The .htaccess file is a small text document that generally sits in the 
same location as your index.php or index.htm pages. It gives you the 
ability to interact with Apache on an individual domain-to-domain and 
directory-to-directory basis.

# This will allow to Redirect index page in site like

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$$1 [R=301,L]

# This will allow you the Redirection on New Domain:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$1 [R=301,L] 

# This will allow you to make All http request to https request for a Domain:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# For PHPFox script:
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://yourdomain/$1 [R,L]  

The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view .htaccess files by default. Once uploaded to the server you can rename the file to .htaccess.

No comments:

Post a Comment