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
-
.htaccess code
I've got a .htaccess file set up on a site to redirect specific old pages to specific new pages on a different site: eg Redirect 301 /oldpage.html https://www.newsite.co.uk/newpage.html Redirect 301 /oldpage2.html https://www.newsite.co.uk/folder/ I have two questions: 1. Is that all the file needs? Or does it need any "rewrite engine on" type code? 2. I would also like to include code to "mop up" any other URLs and redirect them to the root, so that /anyotherpage.html redirects to newsite.co.uk Is there a way to do this?
Technical SEO | | abisti20 -
Hosting Sites under same IP / subdomain usage?
Hello everyone! The company I am working for is working on selling websites templates to clients in the near future. In terms of SEO purposes, would it be detrimental for our clients if we hosted all of these sites under the same server/IP? Also, in the past we've sold sites under a domain we own, adding them on as a subdomain. For example, we would own yourflowers.com, and if Mark's Flowers wanted a site, we would give him: marksflowers.yourflowers.com These sites are going to be the same niche as we are industry specific (example would be, we sell website templates specifically designed for flower shops around the United States). I want the best possible SEO experience for our clients and I believe using subdomains and hosting under the same server IP can be detrimental, but I wanted to see what the Moz community thinks of this. Any feedback is appreciated! Thanks
Technical SEO | | KathleenDC0 -
Looking for a tool that will display the contents of the htaccess file
I am looking for an online tool that will display the contents of the htaccess file. i came across a tool a month ago, but I can not recall the name of the tool. Thanks
Technical SEO | | irvingw0 -
Why are my URL's with a trailing slash still getting indexed even though they are redirected in the .htaccess file?
My .htaccess file is set up to redirect a URL with a trailing / to the URL without the /. However, my SEOmoz crawl diagnostics report is showing both URL's. I took a look at my Google Webmaster account and saw some duplicate META title issues. Same thing, Google Webmaster is showing the URL with the trailing /. My website was live for about 3 days before I added the code to the .htaccess file to remove the trailing /. Is it possible that in those 3 days that both versions were indexed and haven't been removed even though the .htaccess file has been updated?
Technical SEO | | mkhGT0 -
.htaccess: Multiple URLs catches filename
Hi, I have the following line in my .htaccess:
Technical SEO | | rasmusbang
RewriteRule privacy stdpage.php?slug=privacy [L] So if you go to the www.mysite.com/privacy it takes the stdpage.php with the argument above. But if you go to www.mysite.com/privacysssssssss catches the same file. How can I prevent this? It will give me multiple URLs with the exact same content. I have a 404 page which i would like to show instead when the match is not 100%. -Rasmus0 -
A script to automatically write 301 redirect rules to htaccess?
I was wondering if anyone could help provide some resources on how to automatically write 301 redirect rules to htaccess. Allow me to explain... I'm building a new website and the primary users are businesses. They have their own profile pages on the site. The URL is based off of their Company Name. In the event that they decided to change their name... reasons being, perhaps they mispelled it the first time, or they're removing LLC or adding Inc, I want to also change the URL and redirect the old URL to the new URL. Since the URL is based off of their Company Name, making a change to the company name would make a change to the URL. I know it doesn't have to work this way, but for our purpose this works best. In case the old URL had any links to it, I wanted to see if there was an way to automatically update an htaccess file with a 301 redirect from the old URL to the new one. Could anyone point me in the right direction of how to do this? Perhaps a sample script. I've done a lot of searches on Google and can't seem to find anything. e.g. Original:
Technical SEO | | bimmer540
Name: XYZ Widgets
URL: website.com/xyz-widgets New - business changes their company name in their profile:
Name: XYZ Widgets, Inc.
URL: website.com/xyz-widgets-inc Upon the user saving the changes in their profile, I'd like to write a 301 redirect to an htaccess file:
Redirect 301 /xyz-widgets http://www.website.com/xyz-widgets-inc I know how to manually write redirects and I've got a pretty smart web developer. We've just never triggered a script to automatically write to an htaccess file before. Is this possible? Any resources are appreciated. Any security risks? Thanks!0 -
Htaccess redirects how many can i have and does it slow site down
I have had to redesign my site this year www.in2town.co.uk because my hosting company made a huge mistake while trying to update the joomla on my site which resulted in me losing thousands of pages and links. What i would like to know is, i have put some of the old urls in my htaccess file but i would like to know how many old urls i can have in my htaccess file as i am unsure how to use it properly. my idea was, to have some of the lost url links to my site and put them in my htaccess file and have them pointing to similar pages. not sure if this is a good idea or not. i think i have lost a few hundred good links but i would like to know if these urls in the htaccess file would slow down my joomla site any advice would be great.
Technical SEO | | ClaireH-1848860 -
.htaccess and www - non www
Recently I have taken over a website and I made a pretty colossal mistake. The site was properly constructed via .htaccess to a www domain. Typically I roll without it and I made a bad assumption that the .htaccess was not previously set correctly because there were hundreds of fundamental mistakes. After a couple of days I noticed the mistake but some of our new (non www) have picked up some solid links etc. So now I feel that I am in a nightmare of creating redirects etc. So should I switch back to WWW or not? Does it matter at this point?
Technical SEO | | mikeusry0