April 28, 2012 Development no responses # , ,

301 .htaccess Redirect

To prevent getting 404 File Not Found error (traffic coming from links, bookmarks and search engines) when URLs and paths on site have changed, I use .htaccess 301 redirect. Htaccess redirect is better than the meta refresh or redirect tag because there is no delay as the browser reads the .htaccess file first. Here is how it works.

Go to your site’s root folder, download the .htaccess file to your local computer and edit it with a plain-text editor (ie. Notepad). If you are using FTP Client software and you don’t see any .htaccess file on your server, double check your setting and make sure you have turn on invisible / system files.

To Redirect Certain Page(s):

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html<br />
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/<br />

To Redirect Entire Site:

Redirect 301 / http://www.new-site.com/<br />

Redirect with dynamic parameters

For example redirecting http://www.domain.com/brands/sony/sonys-new-s-frames-with-avchd-video-playback/ to http://www.domain.com/sony/sonys-new-s-frames-with-avchd-video-playback/

RewriteRule ^(.*)brands/([a-z_A-Z0-9\-]+)/([a-z_A-Z0-9\-]+)/$ http://%{HTTP_HOST}/$2/$3/ [R=301,L]
RewriteRule ^(.*)([a-z_A-Z0-9\-]+)/([a-z_A-Z0-9\-]+)/([a-z_A-Z0-9\-]+)/$ http://%{HTTP_HOST}/$2/$3/ [R=301,L]
Stay In Touch