Help creating a 301 redirect in my htaccess file
-
Hi Guys,
I'm trying to build a 301 file with the file requirements:
- It should be visible only for Google and other Search Engine Agents.
- It will have a few direct redirects.
- A few URL must be dynamic redirect. For example each page the starts with olddomain.com/category and is not in the list of of direct redirects should be redirect for newdomain.com/category
Here is my start point:
#301 Starts here
Set the agents
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} SlurpMake the direct redirect.
Redirect 301 /category/sub1 http://www.newdomain.com/category/sub1
Redirect 301 /category/sub2 http://www.newdomain.com/category/sub2Redirect everything else
Redirect 301 /category/* http://www.newdomain.com/category
#End of my 301
Will that work how I want? is there anything wrong?
-
Hi Thompson,
Thanks for your input, so I'm planning on eventually do the 301 for everyone. I'm re-designing a big website and not everything is done, but I want users that are looking for the content that I already completed to land in the new site. (because the new site has a much higher conversion rate).
In other hand I have 30% of my traffic in my old site coming from direct visitors, I dont want those visitors to be send to other URL because it would be confusing. however I want people coming from google to go my new site...
Do you think I should sacrifice usability, so I don't risk Google to think I'm trying to do some kind of black hat, strategy.
-
Setting redirects to apply only to search crawlers is pretty much their definition of cloaking, Felip3. The site could end up in a world of hurt if/when caught.
What's the reason for wanting the crawlers to be redirected differently than users? Maybe there's a better way to accomplish what you need in a way that doesn't break their terms of service.
Paul
-
For the directories I think you need to go down the rewrite route. This isn't probably functioning correctly but you get the principle.
RewriteCond %{THE_REQUEST} ^GET\ /category/
RewriteCond %{REQUEST_URI} !^/category/sub1/
RewriteCond %{REQUEST_URI} !^/category/sub2/
RewriteRule ^category/(.*) http://www.newdomain.com/category/$1 [L,R=301]RewriteCond %{THE_REQUEST} ^GET\ /category/sub1
RewriteRule ^category/sub1(.*) http://www.newdomain.com/category/sub1/$1 [L,R=301]RewriteCond %{THE_REQUEST} ^GET\ /category/sub2
RewriteRule ^category/sub2(.*) http://www.newdomain.com/category/sub2/$1 [L,R=301]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Proper 301 redirect code for http to https
I see lots of suggestions on the web for forwarding http to https. I've got several existing sites that want to take advantage of the SSL boost for SEO (however slight) and I don't want to lose SEO placements in the process. I can force all pages to be viewed through the SSL - that's no problem. But for SEO reasons, do I need to do a 301 redirect line of code for every page in the site to the new "https" version? Or is there a way to catch all with one line of code that Google, etc. will recognize & honor?
Technical SEO | | wcksmith10 -
301 Redirect Url Within a Canonical Tag
So this might sounds like a silly question... A client of mine has a duplicate content issue which will be fixed using canonical tags. We are also providing them with an updated URL structure meaning rwe will be having to do lots of 301 redirects. The URL structure is a much larger task that than the duplicate content so i planned to set up the canonicals first. Then it occurred to me id be updating the canonical tags with the urls from the old structure which brings me to my question. Will the canonical tags with the old urls redirect credit to the new urls with the 301? Or should i just wait until we have the new url structure in place and use these new urls in the canonicals? Thanks!
Technical SEO | | NickG-1230 -
Questions about the Sandbox and 301 Redirects
Does the sandbox still exist? What if you have a brand new URL and do a 301 redirect from another website because the name of the service business changed? Thanks for any insight and help.
Technical SEO | | SDSLaw0 -
301 redirect or maual edit of new urls
Hello forum! I will get right to the point,I have a 4 year old PR4 site with lots of links (vacation rentals marketplace, like Homeaway), In about a month from now new CMS will be ready and I will be doing redesign of the site. The problem that I have is (as many of you can guess) losing all the old links that rank high = losing traffic / revenue. Two posiblle solutions here: 1. 301 redirect for each page that ranks high - point it to new url 2. Manually editing new urls created by new CMS and making them to be the same as old ones. This means that some number of urls (the ones that rank high and generate traffic) would be exactly the same while other ones would be generated by CMS thus dufferent in many ways (unicode,different keywords etc.) What would You do here? I am more for 301 redirect but I read all kinds of horror stories in drop of SERP. Thank You for help and advices in advance.
Technical SEO | | Gregos0 -
Page has a 301 redirect, now we want to move it back to it's original place
Hi - This is the first time I've asked a question! My site, www.turnkeylandlords.co.uk is going through a bit of a redesign (for the 2nd time since it launched in July 2012...) First redesign meant we needed to move a page (https://www.turnkeylandlords.co.uk/about-turnkey-mortgages/conveyancing/) from the root to the 'about-us' section. We implemented a 301 redirect and everything went fine. I found out yesterday that the plan is to move this page (and another one as well, but it's the same issue so no point in sharing the URL) back to the root. What do I do? A new 301? Wouldn't this create a loop? Or just delete the original 301? Thanks in advance, Amelia
Technical SEO | | CommT0 -
302 or 301 redirect to https ?
I am redirecting whole site to https. Is there a difference between 302 or 301 redirect for seo? Site never been indexed. Planning to do that with .htaccess command RewriteCond %{HTTPS} !=on
Technical SEO | | Kotkov
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] There are plenty of ways http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html Which way would be the best? Thanks is advance0 -
Setup 301 Redirects
I have been asked to transfer a clients old domain over to a new domain with a new site. All of the inbound links basically go to the homepage, and the few links that dont go to the homepage on the old site, might as well be redirected to the homepage on the new site. I'm wondering is there a "catch all" sort of redirect such as www.oldsite.com/* redirects to newsite.com. So any redirects we havent set up will automatically go to the new site homepage? And secondly, whats the easiest way to the redirects up? Can I just add it as a parked domain or addon domain in cpanel, and do the redirects in there? Or does it needs its own hosting for the old domain with its own htaccess file? Any help appreciated! 🙂
Technical SEO | | timscullin0 -
.htaccess file in wordpress blog
I want to redirect non www to www in blog hosted by wordpress. Where can i find .htaccess file ? Shall i have to create a new one ? If yes, where should i upload it ? Thanks
Technical SEO | | seoug_20050