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
-
Rel Canonical, Follow/No Follow in htaccess?
Very quick question, are rel canonical, follow/no follow tags, etc. written in the htaccess file?
Technical SEO | | moon-boots0 -
Redirection in .htaccess
Hi All, The problem is with the .htaccess file I have written 301 redirection code for Apache server but once I upload .htaccess file from ftp the website is throwing 500 error. Please help as I'm new to the redirection files.
Technical SEO | | Bharath_ATZ0 -
.htaccess Redirect 301 issues
I have completely rewritten my web site, adding structure to the file directories. Subsequently added was Redirect information within the .htaccess file. The following example ...
Technical SEO | | Cyberace
Redirect 301 /armaflex.html http://www.just-insulation.com/002-brands/armaflex.html
Returns this response in the URL bar of ...
http://www.just-insulation.com/002-brands/armaflex.html?file=armaflex
I am at a loss to understand why the suffix "?file=armaflex" is added The following code is inserted at the top of the file ...
RewriteEngine On redirect html pages to the root domain RewriteRule ^index.html$ / [NC,R,L] Force www. prefix in URLs and redirect non-www to www RewriteCond %{http_host} ^just-insulation.com [NC]
RewriteRule ^(.*)$ http://www.just-insulation.com/ [R=301,NC] Any advice would be most welcome.0 -
301 redirect .htaccess
Hi guys I am working on some 301 redirects on an apache webserver and I'd like a bit of assistance in trying to get a specific type result: I want all addresses from domaina.com to be redirected to domainb.com in the same structure so domaina.com/folder/file will go to domainb.com/folder/file expect for 2 folders.
Technical SEO | | seobackbone
ie: DomainA.com --> DomainB.com
except domainA.com/folder1
and domainB.com/folder2 Can someone let me know how I can pull this off?0 -
Htaccess help... I moved my blog from a seperate domain to newdomain.com/blog
Hi, I need help with my htaccess file, I've been told. I moved a blog i had hosted somewhere else to a directory on my ecommerce site. I was told i would need to write something to go in the htaccess file so the sites would not become duplicate content, but I'm a novice and have no idea how to write that code. blog moved from www.whosyourmoondoggie.com to www.moondoggieinc.com/blog Please help, or direct me to the right tutorial 🙂 Thanks! KristyO
Technical SEO | | KristyO0 -
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 -
Please advice needed SSL .htaccess
Hi everyone, I recently installed verisign ssl. the idea to have page https://example.com all redirect from non-http to https work properly, but in IE whenever smbdy types https://www.example.com it shows the red screen with invalid certificate. If you click "proceed" - everything goes to normal page and on server redirect www to non-www seem to work fine. Is there way to get rid of the warning? Is it server or certificate issue? Here is the peice of code from htaccess. Please, advice needed! RewriteEngine On RewriteBase /RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] Thanks in advance
Technical SEO | | Kotkov0 -
.htaccess when integrating one website into another
My client would like to integrate one of it's smaller websites into its main website. I've identified around 20 pages which I'd like to 301 redirect to specific pages on the main website, and this is simple enough. The problem I have is that I am not sure how I can then put a catch-all to redirect all other pages on the site to the homepage of the main website. I'd originally though something like this would work: redirect 301 / http://www.mainwebsite.com/ (catch-all)
Technical SEO | | AndrewAkesson
redirect 301 /about.asp http://www.mainwebsite.com/about (specific redirect 1)
redirect 301 /latest.asp http://www.mainwebsite.com/news (specific redirect 1)
etc. Any ideas?0