General 301 redirection on Apache server using the .htaccess file.
Using the .htaccess file you can:
- Redirect an entire site to a new domain (all urls to be matched on the new domain). Put this directive in the .htaccess file in the root folder of the OLD site:
Redirect 301 / http://www.example.com/
- Redirect an entire site to the homepage of the new domain. Put this directive in the .htaccess file in the root folder of the OLD site:
RewriteEngine On RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
- Redirect a particular page url to a new url on same or new domain.
NB: put this directive in the .htaccess file in the root folder of the OLD site if moving to new domain:Redirect 301 /old-url http://www.example.com/new-url
Pay attention to trailing slashes if moving folder-type urls.
- Change the type of extension for every page, with no other changes.
– E.g. changing all pages from *.html to *.php :RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
– E.g. changing all pages from *.asp to *.php :
RedirectMatch 301 (.*)\.asp$ http://www.example.com$1.php
- Fix canonical issues (www vs non-www urls, multiple homepage uris, etc): See fix-canonical-issues-www-vs-non-www-and-more-on-apache-server
- Strip unwanted query string from urls: See strip-unwanted-query-string-apache
- Get rid of https indexing if no longer needed (applies to the whole site): See 301-redirect-https-to-http-on-apache-server – or vice-versa
Here’s tool to help generate 301 redirections to add to the .htaccess file to do batch url renaming.
It can work for WordPress or any other platform: http://seo-website-designer.com/HtAccess-301-Redirect-Generator