Htaccess redirect, from /year/month to /blog
-
I am trying to make some redirects so we don't lose that SEO juice.
I am trying to move our blog structure from:
http://www.domain.com/2015/09/title-of-blogto:
http://www.domain.com/blog/title-of-blogI need to do redirects in htaccess from the old structure to the new structure but I can't seem to get it working properly. Here is what I have thus far.
<code>RewriteEngine on RewriteBase / RewriteRule ^(.0-9)\/^(.0-9)\$ $1/ [R=301,L]</code>
Any suggestions?
-
This is the right answer minus a few excess characters.
If the blog structure is domain.com/2015/09/title-of-blog then the correct code would be as follows:
RewriteEngine On
RewriteBase /
RewriteRule ^[0-9]+/[0-9]+/(.*)$ blog/$1 [R=301,L]This will result in: domain.com/blog/title-of-blog.
In other words, Peter you had it right but you just had a few extra characters (you assumed the specific day was also included in the URL structure). Yours would work perfectly if the URL structure was domain.com/2015/09/02/title-of-blog
Also, if anyone ever wants to test your rewrite rules this is a great tool. http://htaccess.mwl.be/.
-
Correct code should be:
RewriteEngine On
RewriteBase /
RewriteRule ^[0-9]+/[0-9]+/[0-9]+/(.*)$ blog/$1 [R=301,L]
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
-
Should I redirect a popular but irrelevant blog post to the home page?
Hi. I'm trying to get my website; www.ciphr.com , to rank for keywords relevant to "HR Software" in the UK. It's a highly competitive industry and we rank ~mid to low on page one for some of our ideal keywords that are highly relevant and high volume. Years ago we took the decision to blog about topics more loosely related to the world of work. One of our blog posts, about plants in the office https://www.ciphr.com/advice/plants-in-the-office/ is popular. It gets decent traffic and consistently builds backlinks to the post without any further effort on our part. The specific page has a PA of 46 and DA of 55 with >500 domains linking to it. This compares to our home page with a PA of 47 and 700 linking domains. It is typically the home page that ranks for our money keywords "HR Software" "HR Systems" in the UK. Because this blog post is so loosely related to our actual business, the traffic it generates is highly unlikely to turn into a customer of ours. I am considering redirecting the blog post to the home page to pass link juice to the home page. The concern I have is that, based on the anchor text and contextual signals from linking pages, Google might then infer that our home page is less relevant for our money keywords and more relevant for "plants". Are my concerns unfounded? What are your thoughts? Should I redirect the blog post to the home page? Another internal page? Keep the blog post live? Thanks
On-Page Optimization | | crichardson19922 -
Redirect chains and rankings
Hi All, I've got interesting question for Moz community today. Has redirect chain got any impact on rankings or not? Thank you in advance.
On-Page Optimization | | Optimal_Strategies0 -
Why are http and https pages showing different domain/page authorities?
My website www.aquatell.com was recently moved to the Shopify platform. We chose to use the http domain, because we didn't want to change too much, too quickly by moving to https. Only our shopping cart is using https protocol. We noticed however, that https versions of our non-cart pages were being indexed, so we created canonical tags to point the https version of a page to the http version. What's got me puzzled though, is when I use open site explorer to look at domain/page authority values, I get different scores for the http vs. https version. And the https version is always better. Example: http://www.aquatell.com DA = 21 and https://www.aquatell.com DA = 27. Can somebody please help me make sense of this? Thanks,
On-Page Optimization | | Aquatell1 -
Redirecting to homepage ok?
I deleted a bunch of category pages (renamed mostly actually and thought they'd be auto redirected like my blog posts are but they weren't) so I used a plugin that reroutes any 404 page to the homepage. Is that the best thing to do in this situation? Google Webmasters says there are about 84 404-errors and this should get rid of those right? Is there anything SEO BAD about doing it this way?
On-Page Optimization | | dealblogger0 -
Recommended number of blog posts per page?
Good day! We want to have your suggestions here.
On-Page Optimization | | robinwade
What's your recommended (best) number of blog posts per page? Thanks!0 -
Google found bad links delete them or 301 redirect?
we went into our google account and saw about 70 bad links that they found on our site. what's the best thing to do, seo-wise: should we go into the pages that have the bad links and delete them from the html code, or re-direct them in our htaccess script?
On-Page Optimization | | DerekM880 -
What's the best strategy for reducing the number of links on a blog post?
I'd like to optimize my blog better for search. The first reccomendation I got from my SEOMoz Pro Campaign Crawl was that I needed to reduce the number of links per page on my site. I have lots of links from navigational items in the sidebar that people do click on. I'd really like to keep some or all of the tags and categories I list. Comments are another issue. Most of our posts get about 10 comments. However, our best posts get 50-100 comments. Those comments create a lot of links. I was planning on attempting to reduce the number of links using javascript but I guess Google understands javascript now. I may still do this b/c our pages are huge and some progressive rendering would likely help the user experience. Can you use javascript (ajax or otherwise) to limit the number of links on your page in a way that helps your SEO efforts? Any specific suggestions for reducing links that come from comments and navigational items? How much will reducing the number of links on a given page help with SEO? Any simple way to estimate or quantify this without diving in? Thanks in advance!
On-Page Optimization | | TaitLarson0