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
-
Is 301 redirect the only way when using Vanity URLs?
We have been using vanity urls for some of our pages. Mostly the pages that have a vanity URL have a long URL length. But now the problem is, the vanity URL is getting displayed on the search engine when the particular keyword related to the page is entered. I checked the google search console, the vanity URL is indexed and the original URL remains unindexed. What should I do? Is adding 301 redirect to the vanity URLs are solution? Since some of vanity URLs are not redirecting to the original. Some of the original pages are not getting traffic. Also, can using canonical tag help?
Technical SEO | | tejasbansode0 -
Buying a domain to 301 redirect for increased rankings
A large competitor has recently purchased a large marketing company that specializes in their industry. As a part of this acquisition they obtained ownership of www.digitalsherpa.com, which is now 301 redirecting some 50K links to www.costar.com/. When I did a site:www.digitalsherpa.com search all of the origin URLs had title tags from the costar site in place of their own. My question is: Does this violate Google spam guidelines? search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=site%3Adigitalsherpa.com&oq=site&aqs=chrome.0.69i59j69i57j69i65j69i60j0l2.1919j0j7
Technical SEO | | Reis_Inc.0 -
Migration to New Domain - 301 Redirect Questions
My client is migrating their site to a new domain. I just did a big redesign, including URL structure change, and 301s from old URLs to new URLs. Now they want a new name, so we're moving forward with a new domain name. However, we're going to keep the site on the current domain while we ease customers into the new name. During that time, I'm going to be building links to the new domain name and 301 Redirecting that new one to the current domain name. Then, once we migrate the site to the new domain name, I'm then going to redirect the current domain name to the new domain name. So, my question(s) is/are: Is the above process the best way to use 301 redirects to to build links to the new domain while we transition everything? Should I (or can I) do 3 redirects from the oldest URLs, to the current URLs then to the new URLs? General question... I can't seem to find this anywhere online, but what is the best practice for what order URLs should be in in the htaccess file? Thanks!
Technical SEO | | Kenny-King0 -
301 Redirects in subfolders
Hi, we're making our site into a static site but I would like to transfer the Google juice. Most of the links and database exist on subfolders though. Could I simply do 301 redirects on the subfolders and retain the value or does it have to be on the full domain?
Technical SEO | | Therealmattyd0 -
Virtual inlcude v.s. Redirect 301
Hi there, I manage a website which use a lot virtual includes ( SSI) because it caused a lot of duplicate content i introduced the Canonical url tag. But i still see bad rankings on some pages who are the leading of the virtual includes. Now i'am wondering is it better to remove all the virtual include pages ( url's) and make a redirect 301 of it. Does anybody know that is better for ranking the head page?
Technical SEO | | JoostBruining0 -
Htaccess file
I need to redirect the web pages which do not exist to 404 error the task need to be done in htaccess file. I am using Linux server. the webpages I want to redirect is my domain name followed by question mark e.g. www.mydomain.com/?dfdds I am using the following snippet in my htaccess file, it redirect to bing.com so far, please tell me how to change the snippet so that it redirect to redirect to 404 error page. ========================== RewriteCond %{QUERY_STRING} . RewriteRule .* http://www.bing.com? [L,R]
Technical SEO | | semer0 -
301 redirect on wordpress.com
Hi, How/where do I input a 301 redirect for my http site within wordpress.com. I am already redirecting my wordpress url to myy new non wordpress domain Thanks Lisa
Technical SEO | | lisamarieCunn0 -
Difference between URL Rewrites and 301 Redirects for Rankings
What is the difference between URL rewriting and 301 redirects? Specifically if my home page is rewriting the www. version and the /index.html version rather than 301 redirecting them is this equivalent? Does it still pass the link juice on those alternate variations the same way a 301 redirect will?
Technical SEO | | rcarll0