How to Redirect Htaccess files

Htaccess Redirect

.htaccess files can be used to make redirects. Below are some common examples.
Redirect from old domain to new domain, You can use the code below if you have changed domain and want users on your old domain to be redirected to your new domain.

RewriteEngine on
RewriteRule ^(.*)$ http://www.your-new-domain.com/$1 [R=301,L]

If a user visits http://www.olddomain.com/articles.php he will be redirected to the same page on your-new-domain.com. The R=301 part make it a permanent redirect by sending a “301 Moved Permanently” status code to the user’s browser. If the user happens to visits the same page on your old domain, the browser will automatically redirect to the new domain.

Redirect to www

So you only want users to visit www.mydomain.com and not domain.com? Htaccess redirects can solve this too. Copy the code below into a .htaccess for redirecting all visits to your www domain.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Install ConfigServer

Install ConfigServer Security & Firewall rm -fv csf.tgz wget...

Data Loss

Backups and Data Loss :         Leasedlayer is not responsible for...

DirectAdmin Introduction

DirectAdmin is a graphical web-based web hosting control panel designed to make...

Install Latest RootKit Hunter

Here we instruct that how to install latest released version of RootKit Hunter . Below we have...

Install ffmpeg/ffmpeg-devel on CentOS 5.7 64bit

Installing FFMPEG , FFMPEG DEVEL.1 ) Login in SSH using putty.exe software . With VPS or...

Powered by WHMCompleteSolution