Help writing a .htacess file with the correct 301 redirects
-
Hello
I need help writing a .htaccess file that will do two things.
URL match abc.com and www.abc.com to www.newabc.com
except one subdomain was also changed www.abc.com/blog is now www.newabc.com/newblog
everything after blog matches.
Any help would greatly be appreciated.
Thanks
-
yes ALeyda answer was more concrete for sure Glad to have been of help however
-
Aleyda and Mememax
Thanks very much for the help. Aleyda your answer worked perfectly.
Thanks again!
Chris
-
Hi Chris,
To redirect your old domain to the new domain with the same path for all the URLs except a specific directory, for example: /blog/ that is going to be renamed /newblog/ in your new domain, it will be:
<ifmodule mod_rewrite.c="">RewriteEngine On</ifmodule>
RewriteCond %{REQUEST_URI} ^/blog/(.) [NC]
RewriteRule ^blog/(.)$ http://www.newabc.com/newblog/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^abc.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.abc.com$
RewriteRule (.*)$ http://www.newabc.com/$1 [R=301,L]Thanks,
Aleyda
-
The normal rule to achieve this is:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule (.*) http://www.newabc.com/$1 [R=301,L]For the blog issue you may consider adding an htaccess file in the blog folder and put
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule ^blog(.*) http://www.newabc.com/newblog$1 [R=301,L]or maybe you can achieve that by adding the line:
RewriteRule ^blog(.*) http://www.newabc.com/newblog$1 [R=301,L]
However in this second case you'll have a double redirect: the first which redirect blog to new blog and then the non www to www.
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
-
Recently migrated to https version of volusion site. 301 redirect link chain question
I recently migrated to a https version of a volusion site. They have some type of internal 301 redirect method to accommodate for the entire site. I have also used the 301 redirect manager to redirect categories and pages which I have changed. The question is if I have changed a page internally in the redirect manager from say source. /bluewidget to say. target. /superbluewidget is it wiser or even possible to do it this way to reduce the redirect chain from 3 to 2 steps source. /bluewidget to. target https://www.example/superbluewidget can a relative link be targeted to a full url to reduce steps in a 301 redirect link chain. Thanks
Technical SEO | | mrkingsley0 -
To many 301 redirects
Hi, Is there anything wrong with over 100 301 reditects on my wordpress website and how do you go about redirecting a 301 again for example abc.com redirects to bca.com now i want to redirect bca.com to ert.com any problems with this setup? Regards
Technical SEO | | ReSEOlve0 -
Can new content be added to a url which has a 301 redirect?
I am working on a site which is currently being redesigned. The home page currently ranks highly for relevant search terms, although on the new site the content on this page will be removed. The solution I was considering, to preserve rankings, was to move the content on the home page to a new url, and use a 301 redirect to help preserve rankings for that particular page. The question I have therefore, is am I able to add new content to the home page, and have this page freshly indexed accordingly? Any thoughts or suggestions would be most welcome. Thanks, Matt.
Technical SEO | | MatthewA0 -
Best Place to Redirect 301 to?
Hey Everyone! I have an old site with hundreds of blog posts that are very spammy (duplicate content, keyword stuffed, and just plain bad content). I am going to redirect them and delete them from WordPress but I'm wondering where is the best place to redirect them to? Home page, other posts, other pages...? Any thoughts would be appreciated! Thanks!
Technical SEO | | adamxj21 -
301 Redirect Clarification: Images, Paramter URLs, etc.
I know that going through a site redesign it's essential to make sure that 301s are implemented for any changed URLs, but I wasn't sure if this was the same for the images on the page and the parameter URLs that are created by marketing campaigns - do those URLs also need to be 301 redirected? For example, this URL: www.mysite.com/32-inch-round-aluminum-table/ Could have a parameter at: www.mysite.com/32-inch-round-aluminum-table/?utm_source=twitterfeed&utm_medium=twitter&utm_campaign=Social%3A+My_Site And an image at: www.mysite.com/images/32-inch-round-aluminum-table.jpg Would the first two URLs mentioned need to be redirected to the new URL, and the image redirected to the new image URL? Thanks for the help.
Technical SEO | | eTundra0 -
How long should you keep 301 redirects?
Hi, Back in 2009 I decided to update an older site from .htm and .shtml to .php. In order to minimize the impact I would go in every month and do a 301 redirect on the .shtml page to the new .php page. So I have many that range from 2009 through 2010. I had left the old 301's because I felt they would only be used if needed but I would think I should clean up my .htaccess by removing the old 301 redirects if they are not needed. How long should you keep this type of 301 redirect? Thanks!
Technical SEO | | Force70 -
How long will Google take to stop crawling an old URL once it has been 301 redirected
I need to do a clean-up old urls that have been redirected in sitemap and was wondering about this.
Technical SEO | | Ant-8080 -
301-redirect
Hi My website is fairly new and i wasnt aware of the difference btw 'website.com' and 'www.website.com' when i started up. It doesnt matter which one i use as long as i am consistent right ? Most of my ingoing links are to mainpage on 'website.com'. I have som ingoing links to 'www.website.com' but also some to 'www.website.com/brandname'. is it enough to 301-redir 'www.website.com' to 'website.com' or does it need to be done on several levels ? I need to have someone do the redirect for me - how can i check its working when its done ? Dan Lærum
Technical SEO | | danlae0