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
-
Hreflang usage for language & country x only language
Hi guys, I´m dealing with a website of a client where hreflang tags are implemented as follows: As you can see the hreflang tags reference language & countrycode as well as only the languagecode with the same URL (for french: website/fr/ihr-besuch/online-tickets" hreflang="fr-fr" as well as hreflang="fr" href="https://www.website/fr/ihr-besuch/online-tickets"). Is this a problem and should be corrected so that either language & countrycode is referenced or only languagecode? Thanks in advance!
Technical SEO | | Julisn0 -
Htaccess redirects
Annoyingly it's time to play with this beast again. I've been given the task of doing the following. Keeping the homepage live Redirecting categories to the specific categories on the new site Catch all redirects Now i've managed to setup the specific categories and the catch all redirects, however I am unsure how to keep the homepage live (which is like this:www.domain.com/ so I can't just exclude that?) Would appreciate any help.
Technical SEO | | ThomasHarvey0 -
Htaccess file help
Hi, thanks for looking i am trying (and failing) to write a htaccess for the following scenario <colgroup><col width="679"></colgroup> http://www.gardening-services-edinburgh.com/index.html http://www.gardening-services-edinburgh.com http://www.gardening-services-edinburgh.com/ | so that all of these destinations goto the one resource any ideas? thanks andy
Technical SEO | | McSEO0 -
Htaccess mod rewrite from server address
Hi there, I'm not massively experienced with creating mod rewrite rules and I'm worried I've got this wrong as its slightly different to what I'm used to. The web dev and content creators were working on http://5.10.105.45/~isea/ to create content. I want to redirect all URL's to www.iseasurfwear.co.uk. This is what I've written //Rewrite to www
Technical SEO | | BlueTree_Sean
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^5.10.105.45/~isea/[nc]
RewriteRule ^(.*)$ http://www.iseasurfwear.co.uk/$1 [r=301,nc] Can anyone tell me if this is correct?0 -
Htaccess code to 301 redirect a folder change
Hi, I need some help to redirect all my site as there was a folder change. eg, the old structure was www.mysite.com/stuff-1/bags.html and I need it to go to the same structure without the "-1" eg: /stuff/bags.html
Technical SEO | | Paul_MC
The "bags.html" will be lots of different products, so this would be a wildcard? What would the htaccess code need to be? Thanks0 -
Wordpress Redirect Plugin Vs Manual .htaccess?
Hi everyone, I need to 301 redirect my old pages to new ones but i am confused between whether to choose plugin for this or i should manually rewrite the code on .htaccess file. Please give your suggestion and if you think i should use plugin then which one?
Technical SEO | | himanshu3019890 -
.htaccess help please
Hi there, Can anyone let me know what I need to add to my .htaccess file to make sure that the trailing slash on my domain gets redirected to my main domain name. For example, at the moment Google is seeing my primary domain as follows: http://www.mydomain.com http://www.mydomain.com/ I thought I'd covered off all possible duplication penalities but it look as though I've still got one left! Thanks very much for your help, Simon
Technical SEO | | theshortstack0 -
Redirects on Window Servers - .htaccess equivalent for IIS
I am going to start searching myself, but I have a client on a Windows server needing to do redirects. So besides my usual 'Get a UNIX box', I need to know how to do redirects on IIS. Full site redirect: RewriteCond %{HTTP_HOST} ^[site].com [NC] RewriteRule (.*) http://www.[site]/$1 [L,R=301] as well as page level redirects redirect 301 /[old-page.php] http://www.[site].com/[new-page] And that leads me to the question of RewiteRules also? RewriteRule ^[requested-page].html [server-fed-page].php [L] Thanks if anyone can [redirect] me to a good URL for these. 🙂 Richard
Technical SEO | | Getz.pro0