301 Redirects
This is the cleanest way to redirect a URL. Quick, easy, and search-engine friendly. Remember HTAccess stuff is for Apache servers only.
Redirect a single page
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
Redirect an entire site
This way does it with links intact. That is www.oldsite.com/some/crazy/link.html will become www.newsite.com/some/crazy/link.html. This is extremely helpful when you are just "moving" a site to a new domain. Place this on the OLD site:
Redirect 301 / http://newsite.com/
How would you code a 301 redirect for the following?:
I want to redirect “website.com/” and “website.com/index.html” to “website.com” for the index page to maximize search engine points.
Does this works the same when you use regular expressions? Maybe you should add another example.
You should use RedirectMatch if you wish to use regular expressions.
Yes, this is really useful.
Thanks the first one is useful.. Was using redirection wordpress plugin but it was making my database bulky…
yes, I have apache server, (VPS)
yes, I do have other .htaccess files on it and they all work
no – this redirect line doesn’t do a thing
Works like a charm. Thanks for sharing!
I simply use html redirect pages that look like this:
Forbidden Area
Sorry html code wont show here:
html
head
title Forbidden Area
meta http-equiv=”refresh” content=”0; URL=http://www.The-Site-Name.com
head
body
close body
close html
Are you not losing vital link juice though, as that method won’t tell any existing links that are pointing to the site to look at the new one.
Correct me if I’m wrong.
This is the method I use for redirecting an entire site. It’s especially helpful when you have hundreds of possible URLs on one domain and you want to send them all to a new single location.
redirectMatch 301 ^/ http://newsite.comSometimes you just want to redirect from domain to domain with the permalink structure. Assuming you are able to use mod_rewrite, this should work.
RewriteEngine onRewriteCond %{HTTP_HOST} ^www.oldsite.com$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
Yes this is usefull, but better to giv with DEMO..
Hi how would you 301 redirect
http://www.example.com to example.com
I’m using Codeigniter framework, so i’m not sure if there’s a different process
Thanks it works, I have used it in my website Jay Jalaram Extrusions
By redirecting http://jayjalaramext.com/contact.html which is old one to the new one http://jayjalaramext.com/contact-us
Check it.
Jay
This is exactly what I am trying to do, but am grappling with the example here. I have pages like /contact.html and they need to go to /contact-us as in your example as well as a host of other pages where the file name was changed slightly or in some cases no longer exists.
Can you provide an example of the code you used? Many thanks for any help
@shaneka I think you are looking for the www to no-www snippet.
http://css-tricks.com/snippets/htaccess/www-no-www/
Hi,
Just found this website for snippets. Awesome.
I am having a problem which somebody might be able to help with.
My company has just redeveloped our website. It is going all wordpress. However the initial site was in standard html and css. and we had a blog on a sub domain running wordpress.
The problem now is we have deleted the sub domain for the blog as we are totally switching away from it. Some of its pages are listed in google. How would we redirect from blog.website.com to http://www.website.com using htaccess if no folder or sub domain now exists. Is this even possible?
Will this work for changing “www.sameDomain.com/feature.html” to “www.sameDomain.com/feature.php” ? And would I need to specify every page that the extension has changed?
Hi Richard Razo,
For that canonicalization is the simple way.
I want to block or redirect potentially harmful outgoing flash links that I have no control of from htaccess.
Any Ideas ?
You can block sites that you do not want to have in search engines in robots.txt.
Cause google is the main engine you should also check your website in “google webmaster tools”.
You can block sites that you do not want to have in search engines in robots.txt.
I am having a problem
Redirect 301 /old-folder/page.jsp http://new-site/new-folder1/new-folder2/3d0ce71b-13c1-a0b2-e7c9-5125e3851f2c
Getting
http://new-site/new-folder1/new-folder2/3d0ce71b-13c1-a0b2-e7c9-5125e3851f2c? /old-folder/page.jsp
How can I remove the query string part that automatically concatenating.