How can i redirect URLs with htaccess

.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]

Coding Tag

Coding Tag always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

avatar
  Subscribe  
Notify of