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
-
Where to put 301 redirects in my Wordpress htaccess file?
I have about 25 301 redirects in my Wordpress htaccess file, that look like this: <code>Redirect301/store/index.html https://www.notesinspanish.com/store-home/</code> At the moment they are at the bottom of my htaccess file, below the usual Wordpress rewrite rules: <code># BEGIN WordPress <ifmodulemod_rewrite.c>RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress</ifmodulemod_rewrite.c></code> So they are below all that. Above my WP rewrite rules I have a number of other rules from plugins (caching, ssl). Are my 301's OK where they are at the very bottom of that file? They are working, and redircting pages correctly. Should they be somewhere else? Many thanks for any help. Thanks for any help.
Technical SEO | | Benspain0 -
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 -
What's Worse - 404 errors or a huge .htaccess file
We have changed our site architecture pretty significantly and now have many fewer pages (albeit with more robust content and focused linking). My question is, what should I do about all the 404 errors (keep in mind, I am only finding these in Bing Webmaster tools, not Moz or GWT)? Is it worse to have all those 404 errors (hundreds), or to have a massive htaccess file for pages that are only getting hits by the Bing crawlbot. Any insight would be great. Thanks
Technical SEO | | CleanEdisonInc0 -
.htaccess yikes!
Hi guys, Having a bit of trouble getting a htaccess redirect working. It's very easy but I am making a small typo somewhere! I want to redirect about 400 product pages located at; http://domain.com/product/product-name to http://domain.com/product-name ..basically just dropping /product/ Any help would be appreciated as my errors in Moz are all over the place!
Technical SEO | | MrPenguin0 -
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 -
Help needed please with 301 redirects in htaccess file.
In summary, we're currently having issues with our htaccess file. 301 redirects are going through to the new described URL but in addition the new URL is followed by a ? and the old URL. How can we get rid of the ? and previous URL so they don't appear as an ending. None of the examples we've found re this issue online appear to work. Can anyone please offer some advice? Can we use a RewriteRule to stop this happening? Here's a summary of the htaccess file REDIRECT CODE BEGINS HERE LONG LIST OF REDIRECTS, which appear to be set up perfectly fine. REDIRECT CODE ENDS DirectoryIndex index.php <ifmodule mod_rewrite.c="">RewriteEngine On Options +FollowSymLinks
Technical SEO | | petersommertravels
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(images|system|themes|pdf|favicon.ico|robots.txt|index.php) [NC]
RewriteRule ^.htaccess$ - [F]
RewriteRule ^favicon.ico - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]</ifmodule> DirectoryIndex index.php0 -
Converting files from .html to .php or editing .htaccess file
Good day all, I have a bunch of files that are .html and I want to add some .php to them. It seems my 2 options are Convert .html to .php and 301 redirect or add this line of code to my .htaccess file and keep all files that are .html as .html AddType application/x-httpd-php .html My gut is that the 2nd way is better so as not alter any SEO rankings, but wanted to see if anybody had any experience with this line of code in their .htaccess file as definitely don't wan to mess up my entire site 🙂 Thanks for any help! John
Technical SEO | | JohnHerrigel0 -
Htaccess 301s to 3 different sites
Hi, I'm an htaccess newbie, and I have to redirect and split traffic to three new domains from site A. The original home page has most of the inbound links so I've set up a 301 that goes to site B, the new corporate domain. Options +FollowSymLinks
Technical SEO | | ellenru
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] Brand websites C and D need 301s for their folders in site A but I have no idea how to write that in relationship to the first redirect, which really is about the home page, contact and only a few other pages. The urls are duplicates except for the new domain names. They're all on Linux..Site A is about 150 pages, should I write it by page, or can I do some kind of catch all (the first 301) plus the two folders? I'd really appreciate any insight you have and especially if you can show me how to write it. Thanks 🙂0