RewriteQueryString and .htaccess usage
-
I'm trying to redirect a whole load of pages which use a query string to a different directory for example.
Original URL: example.com/news/post.php?s=2011-01-28-some-text
New URL: example.com/blog/post.php?s=2011-01-28-some-text
My understanding is that because the url uses query strings I need to use a rewrite rather than the usual redirect 301 etc. I've come up with this but it is not doing the job. Any ideas what I'm doing wrong?
RewriteEngine On
RewriteCond %{QUERY_STRING} s=
RewriteRule ^/news /blog [L,R=301] -
Hi Jarno,
This worked perfectly, thank you!
All the best,
Rodney
-
Rodney,
I believe you have the use the $ symbol for following the content and using the ^ symbol I always start off by using the base URL. You could try:
RewriteEngine on
Options MultiViews FollowSymLinks
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule (.) http://www.example.com/$1 [R=301,L]
RewriteRule ^news(.) http://www.example.com/blog$1 [R=301,L]I think this should do the trick.
regards
Jarno
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
-
Set Up htaccess File
Looking for expert help (willing to pay) to set up a proper htaccess file. I'm having an issue as the site has a subdomain at secure.domain.com and has php extensions there. I tried a couple recommended code sets but it seems to be a mess. The site is working properly but this may be causing rankings issues. It's coded in pure HTML and PHP, no Wordpress stuff.
Technical SEO | | execubob
The delete www causes the secure side to fail. The delete html extensions causes the php extensions to fail.0 -
How important is keyword usage in the URL?
Hi,
Technical SEO | | Whebb
We have a client who has engaged us recently for some SEO work and most of their website looks pretty good seo-wise already. Many of their site pages rank at the top or middle of page two for their targeted keywords. In many cases they are not using the targeted keyword in the URL and most pages could use some additional on-page clean up. My question is, is it worth it to re-write the URLs to include the targeted keyword and then do 301 redirects to send the old pages to the new ones in order to improve the ranking? Or should we just do the minor on page work in hopes that this will be enough to improve the rankings and push them on to the first page. Thanks.0 -
Pointing a sub-domain to a sub-folder in htaccess
I have a client who currently uses shopify for there blog. I want to set them up with a separate blog away from the shopify system and host it in Australia. I know the best option is using a subfolder but as the shopify system is an unmoveable CMS can I somehow point my subdomain to a subfolder and get the benefits of the domain name? I could do this by using the rewrite rule in the htaccess file. If I was to do this would it end up cloaking the URL's of the articles?
Technical SEO | | acs1110 -
.htaccess and error 404
Hi, I permit to contact the community again because you have good and quick answer ! Yesterday, I lost the file .htaccess on my server. Right now, only the home page is working and the other pages give me this message : Not Found The requested URL /freshadmin/user/login/ was not found on this server Could you help me please? Thanks
Technical SEO | | Probikeshop0 -
Need Help writing 301 redirects in .htaccess file
SEOmoz tool shows me 2 errors for duplicate content pages (www.abc.com and www.abc.com/index.html). I believe, the solution to this is writing 301 redirects I need two 301 redirects 1. abc.com to www.abc.com 2. /index.html to / (which is www.abc.com/index.html to www.abc.com) The code that I currently have is ................................................... RewriteEngine On
Technical SEO | | WebsiteEditor
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule (.*) http://www.abc.com/$1 [R=301,L] Redirect 301 http://www.abc.com/index.html http://www.abc.com ...................................................... but this does not redirect /index.html to abc.com. What is wrong here? Please help.0 -
Navigating The New Rules - Clarification on NoFollow Usage
I posted some of this elsewhere but would like feedback from some of SEOMoz community. An author. Lets say she has a book out on Relationship Advice.
Technical SEO | | CarlosFernandes
Lets say her book was even called Relationship Help, Advice and Tips. She promotes it for years on her website and implements an affiliate program to get wider reach. Affiliates link to it by the name of the book. One day she even gets a mention or two on a few Yahoo editorial type pages that reviewed said book. A few other very big name websites also link to her and even link to her (without her asking) to her domain no less and make the link say simply Relationship Advice. The links were in the body of the pages. Again, these were unsolicited reviews that she did not even ask for. In the old world - that was ok - in as much as unharmful to her site. In the new world she's toast. She has taken down the book pages she worked 7 years to build up. I don't even think that will help. People linked to her website and put "relationship Advice" in the links because that's what she gave and was an expert at. She didn't ask for those links.
2) A large well known web directory that many have heard of - choose to charge for inclusion into their directory. BUT - you can get a free link if you include some code on your website. A reciprocation that is well known. I have read many many articles and posts by many people over the years on this - and as far as I can tell that reciprocation model for free submission was OK. As long as directories didn't have search functions that served search results that were biased to paid link submissions they seemed to be ok. In terms of the free submission - I read a post way back by Matt that said as long as the directory wasn't asking for the reciprocal link in addition to charging for the submission - that was OK. So, scoot forward to 2012. Said directory has hundreds of thousands of links to it - due tot he reciprocal code that was on many of the free links. The code on the websites that got free links obviously promotes the directory by putting the main keyword in the link. ie "Web Directory". In this new world - is this OK ? That's what they do. They are after all a web directory? The company in scenario 2 with hundreds of thousands of links all saying virtually the same phrase - with the vast majority of the backlinks being from generated reciprocal links for free advertisers in its directory - they are doing FINE. Not hurt at all. The small business owner / author in scenario 1 - who had unsolicited natural links coming to her with anchor text detailing something she did and was an expert at - has gone from the SERPS. Should the company in Scenario 2 - that COULD DO something about the anchor text in the reciprocal links back to their website - now change the recip code so that it just says their brand name instead of "web directory" ? Should the author - if she ever regains from this hell - now have some kind of policy clearly stated on her website - that if any person is ever to link to her website ever again - they MUST only link to it with her name in the anchor text - and never link up words she is an authority on? How can she prevent that? So now is it up to the advertiser or the publisher to ensure we are all safe? If small business person Billy Bob inquires about a paid link on a website and the publisher dosn't tell him that the link may hurt his site and he does not not request a NOFOLLOW on it (because he is just a clueless business owner) - are they (the publishing website) liable for Billy Bob's site tanking if it does? Or is it the advertiser's job to be aware of all said issues - because I know the vast majority of Billy Bob's wouldn't be. How long has everyone got to "get in line"? There are many in the search community offering paid links on their websites in "Sponsored Links" sections - without the use of NOFOLLOWS and i don't see any devaluing of their advertisers websites. If rules are rules let everyone play them. Getting sick of the hypocrisy. I aim to get to Journeyman though just so I can get a DOFOLLOW link on this site 🙂 Incentives eh! Carlos1 -
Remove a directory using htaccess
Hi, Can someone tell me if there's a way using htaccess to say that everything in a particular directory, let's call it "A", is gone (http 410 code)? i.e. all the links should be de-indexed? Right now, I'm using the robots file to deny access. I'm not sure if it's the right thing to do since Google webmaster tools is showing me the link as indexed still and a 403 error code. Thanks.
Technical SEO | | webtarget0 -
301 redirect .htaccess problem
Can anyone explain to me why this doesn't work? Redirect 301 /category/diamond-pendants/nstart/1/start/(.*) http://www.povada.com/category/pendants/nstart/1/start/$1 Im trying to replace everything after /start/ and insert it into the new url. Thanks in advance.
Technical SEO | | 13375auc30