How to redirect properly using htaccess?

Member

by delpha , in category: SEO , a year ago

How to redirect properly using htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by elmo.conroy , a year ago

@delpha 

To redirect properly using .htaccess, you can use the following methods:

  1. Redirect a specific URL to another URL:
1
Redirect /old-page.html http://example.com/new-page.html


This will redirect the URL "/old-page.html" to "http://example.com/new-page.html".

  1. Redirect an entire domain to a new domain:
1
Redirect 301 / http://newdomain.com/


This will redirect all requests to the old domain to the new domain with a 301 status code (permanent redirect).

  1. Redirect non-www to www or vice versa:
1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]


This will redirect requests from "www.example.com" to "example.com" or vice versa using a 301 status code.

  1. Redirect with a Rewrite rule:
1
2
RewriteEngine On
RewriteRule ^old-page.html$ /new-page.html [R=301,L]


This will redirect the URL "/old-page.html" to "/new-page.html" using a Rewrite rule and a 301 status code.


Note: Make sure to backup your .htaccess file before making any changes and test the redirects to ensure they are working as expected.