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.
That sounds more like a job for a canonical.
I’m not understanding your question. The format for 301 redirects are:
Redirect 301 missingFile.html http://www.example.com/newFile.html
Best,
Rob Broadwell
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
Did you restart apache after adding the redirect?
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.
Tims method will drop your SEO rankings as it transfers 0% of the link juice on that page. Using a 301 redirect as stated in this post, it will pass on over 90% of all link juice.
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.com
Sometimes 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 on
RewriteCond %{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
Hi,
try this in .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,QSA,L]
It might work for your query..
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.
ooh wrong direct will try another page
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?
Yes you would use Redirect 301 /oldpage/ http://example.com/newpage/ as I need to do exactly the same thing on a site I’m converting to WordPress. It is precisely because the old url doesn’t work that you tell the search engines what the new url is to replace it. Did you manage to get this working?
The issue for me is the amount of time it is going to take to redirect every single old page to the new page as the old site structure was different, sigh..
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.
The question sometimes arrises with clients “How permanent is a 301 permanent redirect?” Anotherwords, if at some future point, the client changes their mind for whatever reason, what are the consequences of changing a “permanent” redirect?
What is the basic difference between a mod rewrite and a 301 rewrite? Ive been using mod rewrite method in htaccess.
Hi , I got this code to redirect domain.com/index to domain.com, but does not work. Can anyone tell me why?
Below is the code
RewriteCond %{THE_REQUEST} ^./index
RewriteRule ^(.)index$ http://www.gsblagna.com/$1 [R=301]
thanks you very helpful i used the simple one line
Redirect 301 /sample.html http://www.newsite.com
thanks for sharing
Could this be applied to redirect from non www to www ? Something like:
Redirect 301 myDomain.com http://www.myDomain.com
or the short version: Redirect 301 / http://myDomain.com/
Could this work? is it necessary to include http:// ?
Yes it is necessary to include http://.
Well i am transfering all of my data from old site to new one. including posts. i.e. i want to on site A there was a page called /mypage.html and i want that when user click on this url from search page it will be redirect to new site containing same page. I tried to do a 301 redirect using ” But its redirecting only main domain, please help me how can i redirect posts too? Regards
Redirects are great in terms of SEO and specifically 301 as opposed to 302. That said, you need to refrain from using redirects whenever possible because they don’t really retain all your Google juice. Just be sure to use it as last resort rather than a primal one. Again, I’m talking specifically about the search engine optimization aspect of the matter.
This is a must if you’re moving pages and don’t want to have a bunch of dead links. I use SEO spider to map all URLs on old website and then create 301 redirection for the one that don’t match anymore.
I used
RewriteCond %{THE_REQUEST} \/index.html\ HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]
to remove index.html,
and to redirect used
Redirect 301 /old-file.html http://mywebsite.com (It works)
But issue is,
I just want to redirect
Someone please help me. I have a website that was done in coldfusion and I am trying to redirect to an html page. I have two problems, however: one problem is the following:
Redirect 301 /tax_glossary.cfm http://www.mysite.com [R=301,L]
and the other is:
Redirect 301 /Margin-Accounts.9.htm http://www.mysite.com/margin-accounts.html [R=301,L]
I have this at the beginning of the htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule http://www.mysite.com [R=301,L]
I keep getting an internal server error.
Any help would be greatly appreciated.
Thank you
remove “L” parameter.
Like:
RewriteRule ^branches/kl$ /branches.php?s=kl [R=301]
What about 301 redirects with masking enabled?
How do I get this to work when the directory being redirected has hyphens? So:
http://www.example.org/about/move-consultant-team/name-ofperson
to
http://www.example.org/about/consultants/name-ofperson
Thank you but how do i do some thing like
redirecting
site1.com/pagename.html
to
othersite.com/pagename.html
and i have many urls like this with only domain change
I personally think using the htaccess method works better. Always do this on all my sites and have had no problems.
How to redirect this url
from http://www.thexyz.com/our-brands.php (url not working)
to http://www.xyz.com/our-brands.php (live url)
Hi,
i have a query regarding redirection.
i have site A and right now i redirected to Site B 301 permanent redirection.
Now in site A i have a folder called “test” but that should not get redirect to Site B…
how to stop avoiding from site A/particular folder to site B…
we don have that folder in Site B so i am getting not found error.
and i don want that folder url should not get redirect.. how to over come from this prob…
Need help …………
If you’re keeping your same domain name and moving from a HTML site to a WP site, we’re manually coding in the 301’s. But, we have a WP blog on this HTML site that we added about a year ago, so the URL structure is domain.com/blog/title-of-article-here/ and we’re getting ready to remove the /blog directory since we don’t need it as the new website will be 100% WordPress. For this redirect sequence, we’re going to use the Simple 301 Redirects plugin which will now point domain.com/blog/title-of-article-here/ to domain.com/title-of-article-here/ to shorten the URL and make it a more focused URL for Google to see and have more of the article titles display in the SERPs. This is why we’re loving WordPress sites! – Patrick
I currently have a redirect set up as follows
Redirect 301 /gb/41-fire-refuge-safety-signs http://rainbowsafety.co.uk/41-fire-refuge-safety-signs
The above redirect works fine, however when I type in http://astonsafetysigns.co.uk/gb/41-fire-refuge-safety-signs
I am redirected to http://rainbowsafety.co.uk/41-fire-refuge-safety-signs
and want to be redirected to http://astonsafetysigns.co.uk/41-fire-refuge-safety-signs
Is there a way in which this can be achieved?
Hi Jon.
I am having a very similar issue. Did you manage to get this solved?
If so, could you post the solution please, it would be a massive help?
Many thanks in advance
Neil.
I have an Ubuntu 12.04 box running 3 sites. One of them I need to force to use http://www.site.com vs just site.com. I have mod_rewrite is running and I have placed a .htaccess file in my /var/www/site directory with this code in it and restarted apache. Nothing, no effect. I even change the redirect to point at google just trying to see if it was working at all. Nothing. Any suggestions, do I have it in the wrong directory.. etc..
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
How do I redirect all 404 errors in wordpress to my homepage?
Do I have to do this in htaccess or some other place?
Tried this code but it is not working :
RewriteEngine on
ErrorDocument 404 /index.php
I use the 301 redirect to remove “www” from the domain name. I noticed that css-tricks also have your “www” removed. I wonder if that have an effect on page popularity (link history) for older web pages with “www”.
How to redirect /~benchmak/catalog.html?page=shop.browse&category_id=62 to http://sitename.com/showroom/catalog ?
Any help would be appreciated .
Thanks in advance.
Hi there, hope that someone knows what I’m doing wrong:
I have an old site (www.tehnomarket.com) that I would like to redirect to a new one (www.tehnomarket.com/novi), but when I try to do it like this it just goes into an infinite loop:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.tehnomarket.com$ [OR]
RewriteCond %{HTTP_HOST} ^tehnomarket.com$
RewriteRule ^(.*)$ http://www.tehnomarket.com/novi/index.php/$1 [R=301,L]
Thx :)
Simple yet effective. Thanks!
Scrolled allllll the way down here just so I could say THANKS!
Hi this is hrithik ..can somebody help me how to redirect magento product urls to wordpress woocommerce urls
simply like http://example.com/index.php/shop/category/test1.html to http://example.us/shop/category/test1/
we have bulk of products ( ~3000 products )which need 301 redirects
Hi there,
I’m redesigning an old website entirely with WordPress. Urls will obviously be different. The current website has very good ranking in Google, will the method mentioned above keep the good ranking and seo the website currently has?
Thanks!
Am changing my site from html4 to html5 with a new directory. Content in all pages will remain the same but page URLs will all be different.
Do I have to do a .htaccess file 301 Redirect for all the existing pages (to the new page) so status on search will remain the same (presumably) following the transition?
Can give example code for a page?
Thank you
Ok have html site – want to keep it’s index/.com but have all it’s subpages redirect to a WP site you see
Is there a method to do this that is easy
Cheers
Sorry if i am out i have thousands error 400 by changing the name of the redirect php file i have. problem is all error links does not exsist in my domain.
Never had these links. Any way how can i redirect 301 with some lines all of them to my site, they all start with the same link, example:
redirect.php?url=http://www.acidicredhosting.space/acenet-web-hosting-allytech-cloud-web-hosting
redirect.php?url=http://www.acidicredhosting.space/fast-web-hosting-uk-cheap-web-host-providers
As you see all start with this redirect.php?url=
Thanks
Forget to mention if this can be made with htacces?
hello all, i need the redirect to work based on the query string, for example how would I redirect this:
http://website.com/s/314/index3.aspx?sid=314&gid=1&pgid=1234
into this:
http://website.com/new-url/goes-here/
The new website is a WP site
Thanks!
If you want to test for 301 redirect or for any type of redirect you can use the redirect checker – https://www.minfolo.com/seo/redirect-checker
Thank you!
Are you sure the whole URL is required if I’m redirecting within the same domain?
I’m having trouble finding an example for redirecting a directory (not just a single page) from one website to a directory at another domain. To be specific, I want
website.com/pettit/
to go todifferent-website.com/PETTIT/
– I’m doing it with an HTML redirect but would rather use .htaccess. Thanks!abc.com/company
abc.com/company-profile.php
how to redirect from company to company-profile.php page on same domain.
Hello – My 301 redirects are not working. Can you help me with the correct code? Here is my htaccess code:
BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
// redacted
END WordPress
Hey Todd! Since you’re using WordPress, I’d suggest using this plugin to create redirects: https://wordpress.org/plugins/redirection/
It makes both creating and managing redirects easier and more maintainable since it can be done directly in the WP admin.
This would be enough:
Redirect 301 /oldpage.html /newpage.html
No need to write the whole url
All the posts I want to redirect have the same title but drop the category in the URL. Is there a way to automatically redirect olddomain.com/category/postname to newdomain.com/postname without doing each post individually?
I’m somewhat a noob on this. So with this
Redirect 301 / http://newsite.com/
1) would that code direct all traffic to the new site and keep the same url structure… i.e. “https://OLDsite.com/category/post-hello” will 301 to “https://NEWsite.com/category/post-hello”
2) will that / could that direct all http and https to https of the new site?
3) will this keep all SEO juice in tact for each page?
4) how long should it stay in place for SEO purposes?
thanks for any help!
I found out that usage of “Redirect 301” is very confusing and my redirects were not working. For example:
Redirect 301 /oldpage /newpage
Surprisingly, it will redirect all old subpages to new subpages. In particular it will redirect /oldpage/page1 to /newpage/page1 Therefore better to use RedirectMatch docs here ( https://docs.oracle.com/cd/B14099_19/web.1012/q20206/mod/mod_alias.html ) or RewriteRule (generator here https://www.301-redirect.online/htaccess-301-redirect-rewrite-rule-generator )
Hi, with a 301, I redirect friendsofcoffee.nl to misterbarish.nl.
I use the .htaccess file for the redirect with following code:
Also tried this:
Also tried this:
Also tried this
But search console gives me the following error message:
I tested the status code using https://httpstatus.io/
What is going wrong?
I prepared this very thoroughly because I really don’t want to lose rankings.
Do you have an idea? Is it the coding in the .htaccess file?
Help is highly appreciated!!!! Thank you
Happy greetz,
Tim
thanks it was a great and in deep deatail
i have aquestion??
i have to delet tags pages from a website
all of them are dublicate pages and we need to redirect them – 301 redirect
so how can i do it?
all them are indexed on google and they have PA or UR – link power
1-rdirect tag 2- do not delet tag from article posts 3- do not elet them from wordpress panel 4- do not delet them from site map
or or or
1-make them 404 – i mean delet them from wordpres panel -delet them from articles – delet them from sitemap
2- do 301 redirecet
which is better for me?
thanks semrush
i love your tools
I have multiple websites. One of them has about 180 pages and has been around for many years. It also has accumulated over 2000 backlinks. I am about upload a completly updated version of this site. For better security, it will change from http://mysite.com to https:mysite.com. In the new version, the file extension for all pages will also change from HTML to PHP. What is the best way to use 301 Redirects to maintain all of my backlinks? Any suggestions would be sincerely appreciated.
I have tested some relevant htaccess rewrite rules using https://htaccess.madewithlove.be/. There is both good news and bad news. Here are the results.
EXAMPLE 1 (successful)
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
http://mysite.com/ resolves to https://mysite.com/
and
http://www.mysite.com/ resolves to https://mysite.com/
EXAMPLE 2 (successful)
RewriteEngine On
RewriteRule ^A.* /B[R=301]
http://mysite.com/A/ resolves to http://mysite.com/B%5BR=301%5D
EXAMPLE 3 (successful)
Redirect 301 /A/ /B/
http://mysite.com/A/ resolves to http://mysite.com/B/
HOWEVER, if I try to use the rules in EXAMPLE 1 with those of EXAMPLE 2 or EXAMPLE 3, only the rules of EXAMPLE 1 produce the proper result. Do you know why the rules in EXAMPLE 1 seem to be incompatible with the others? This is important as I have many URLs that need to be redirected.
Thanks in advance for any assistance!
Thanks the first one is useful.. Was using redirection wordpress plugin but it was making my database bulky
Thank you I used the Redirect old folder to new folder, and it worked perfectly!
Best wishes,