How can i redirect URLs with htaccess

by Yogesh Khanna 29-May-18

0 1018


.htaccess is used on web server which are running Apache Web Server Software. It is a configuration file.
It is used to alter the configuration i.e. to enable or disable the additional functionality and also features that are offered by the Apache Web Server Software.

For example, if you want to redirect the website to a particular link then you should write the below code in your .htaccess file:-

Redirect to same website file
Redirect /path/old.html  /path/new.html

Redirect to external website
Redirect /path/old.html  http://www.website-name.com/path/new.html

Redirect error message (404 errors)
ErrorDocument 404 http://website-name.com/

Add www in URL
RewriteEngine On RewriteCond %{HTTP_HOST} ^website-name.com RewriteRule (.*) http://www.website-name.com/$1 [R=301,L]

How remove www in URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]


Share:


Comments

    Waiting for your comments

Leave a Reply