Redirecting from one URL to another using .htaccess

If you are looking to redirect traffic from one domain to another, the easiest way would be to edit the .htaccess file located by default in the /var/www/html/ directory.

The .htaccess file uses mod_rewrite and should look like the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


To redirect traffic to another domain, add the following rewrite rule underneath the last line of the example config:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} testsite\.net$ [NC]
RewriteRule ^(.*)$ [L,R=301]


Once added, restart apache and thats it.

Hope this helped.

No token or token has expired.

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP troubleshooting tip

27th Nov 2018