Endire
Elite Member
- Mar 27, 2012
- 1,756
- 1,075
I see a lot of questions from those new to SEO and IM about redirecting URLs so I thought I would share some common tips. Enjoy!
Redirecting URL?s
What are the basic kinds of redirects?
Just in case you your knowledge is lacking on redirects, I thought I would mention all the different methods for achieving a redirect.
301 redirect: Also known as a permanent redirect, the 301 is a code that signals to search engines and other bots that a page has permanently moved to the new location where visitors are being redirected to. The 301 is an http status code (just like 404 (page not found) or 500 (server error)). Redirecting using this method is thought to be the best for SEO because link authority is passed to the URL being redirected to.
302 redirect: Also known as a temporary redirect. In http version 1.0, status code means ?temporarily moved? in http 1.1 status code means ?found?. In general, this redirect should not be used. It passes zero link authority to the URL being redirected to.
Meta Refresh: These are redirects executed at the page level as opposed to ones executed at the server level. They are generally not recommended although they do pass on some link authority. They are a poor method in terms of usability because they are slower and can increase load times.
Best Practices for using the 301 when moving a website:
One of the most common uses for a redirect is when moving a website. To create the best user experience, redirect like URL?s to like URL?s. For example www.example.com/widgets.htm to www.example.com/new_site/widgets.htm. Remember that users expect to see content based on what they read in a meta description on a search engine results page. Redirecting all old URLs to the home page of a new site (while easier) does not promote a good user experience and may increase bounce rate.
If you are redirecting URL?s via .htaccess and you have a lot of them, remember that directives in this file are executed in the order that they are written. This means you should not place shorter URLs before longer ones that have a similar file path. For instance placing www.example.com/aboutus before www.example.com/aboutus/contactus.htm will redirect both URLs to whatever domain was specified for /aboutus.
Simple Snippets
Here are some basic redirects that can be used in .htaccess. Remember that when using .htaccess, you have to tell the file to turn rewrite on.
RewriteEngine On
Boom, done.
Changing the file extensions of your pages (for instance html to php). You can modify this to your needs such as if you want to redirect html pages to asp pages or php pages to .asp pages or whatever.
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [R=301, L]
Force www in your URL?s
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ [block]5[/block] [R=301,L]
Redirect index.php to the root
Options +FollowSymLinks DirectoryIndex index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
Map 404 errors to a custom page (remember to name your file accordingly or change the page it redirects to if your file is not named 404.html)
ErrorDocument 404 errors/404.html
Regular Expressions
You can save a lot of time and headache by reading up a little on regular expressions before you start building your configuration file.
Here are some great resources on regular expressions.
Basic info can be found at http://vertstudios.com/blog/introduction-to-regular-expressions/
More advanced info can be found at http://www.regular-expressions.info/
Do you have any redirect tricks for SEO that have helped you?
Redirecting URL?s
What are the basic kinds of redirects?
Just in case you your knowledge is lacking on redirects, I thought I would mention all the different methods for achieving a redirect.
301 redirect: Also known as a permanent redirect, the 301 is a code that signals to search engines and other bots that a page has permanently moved to the new location where visitors are being redirected to. The 301 is an http status code (just like 404 (page not found) or 500 (server error)). Redirecting using this method is thought to be the best for SEO because link authority is passed to the URL being redirected to.
302 redirect: Also known as a temporary redirect. In http version 1.0, status code means ?temporarily moved? in http 1.1 status code means ?found?. In general, this redirect should not be used. It passes zero link authority to the URL being redirected to.
Meta Refresh: These are redirects executed at the page level as opposed to ones executed at the server level. They are generally not recommended although they do pass on some link authority. They are a poor method in terms of usability because they are slower and can increase load times.
Best Practices for using the 301 when moving a website:
One of the most common uses for a redirect is when moving a website. To create the best user experience, redirect like URL?s to like URL?s. For example www.example.com/widgets.htm to www.example.com/new_site/widgets.htm. Remember that users expect to see content based on what they read in a meta description on a search engine results page. Redirecting all old URLs to the home page of a new site (while easier) does not promote a good user experience and may increase bounce rate.
If you are redirecting URL?s via .htaccess and you have a lot of them, remember that directives in this file are executed in the order that they are written. This means you should not place shorter URLs before longer ones that have a similar file path. For instance placing www.example.com/aboutus before www.example.com/aboutus/contactus.htm will redirect both URLs to whatever domain was specified for /aboutus.
Simple Snippets
Here are some basic redirects that can be used in .htaccess. Remember that when using .htaccess, you have to tell the file to turn rewrite on.
RewriteEngine On
Boom, done.
Changing the file extensions of your pages (for instance html to php). You can modify this to your needs such as if you want to redirect html pages to asp pages or php pages to .asp pages or whatever.
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [R=301, L]
Force www in your URL?s
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ [block]5[/block] [R=301,L]
Redirect index.php to the root
Options +FollowSymLinks DirectoryIndex index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
Map 404 errors to a custom page (remember to name your file accordingly or change the page it redirects to if your file is not named 404.html)
ErrorDocument 404 errors/404.html
Regular Expressions
You can save a lot of time and headache by reading up a little on regular expressions before you start building your configuration file.
Here are some great resources on regular expressions.
Basic info can be found at http://vertstudios.com/blog/introduction-to-regular-expressions/
More advanced info can be found at http://www.regular-expressions.info/
Do you have any redirect tricks for SEO that have helped you?