301 Redirect htaccess
-
Hi Guys,
I have a website that has plenty of links with parameters. For example:
http://www.domainname.co.uk/index.php?app=ecom&ns=catshow&ref=Brandname-Golf-Shorts&sid=201v04gxs2hlozv161tfo43qk98583elI want to place a wildcard redirect on the .htaccess but don't know what exactly code for this. Ideally I want the URLs above to be:
http://www.domainname.co.uk/Category/Brandname-Golf-Shorts
Any help pls.
Thanks,
Brucz -
Hi Mark, has your question been answered?
-
Hey Mark,
did this work for you?
Would be happy to hear back.In the meantime enjoy your weekend
Christoph
-
Hey Mark,
it is only 07:21 right now, but I updated my original answer.
Hope you still accept my premature answer
Christoph
-
Hey Christoph,
No worries, yes anything pre 8am is a risk (coffee depending)!
Look forward to your next deep post 8am comment
Cheers
Mark
-
Hey Mark,
I should not answer questions in around 6 a.m. Sorry for that
My example works only when you want to redirect from an old domain to a new one - or from http://www.domain.com to http://domain.com
If you want the links to be on the same domain, things get tricky quite fast. I'll deep dive into the documentation and be right back
-
Hey Christoph,
Glad our needs can spring you into action
Appreciate that very much, will test it out in the morning and post my findings.
Thanks again, thats great.
Mark
-
Hey Mark,
Finally a question that I can answer (yay!)
I use the following code on my website:
<ifmodule mod_rewrite.c="">RewriteEngine On
RewriteRule ^(.*)$ http://www.it-engelhardt.de/$1 [R=301]</ifmodule>It basically takes every URL like http://itengelhardt.de/microconf-2013-hub-page/
and just redirects it (301 of course!) to http://www.it-engelhardt.de/microconf-2013-hub-page/
UPDATE 1: (after carefully re-reading the question)
OK, hopefully this is the correct answer to your question:
**Assumptions I made: **
- You want to extract the category name from the query string (i.e. everything after the '?')
- "ns=catshow" in the query string stands for "category show" and tells the server to show a category
Then this is hopefully what you want:
RewriteCond %{QUERY_STRING} ns=catshow
RewriteCond %{QUERY_STRING} ref=([^&]+)
RewriteRule ^index.php /Category/%1? [R=301]**What it does: **
- checks if "ns=catshow" is present in the query string
- extracts the value from the "ref=" variable in the query string and stores it in %1
- rewrites every request to the server, that matches conditions 1. and 2. and starts with "index.php" to /Category/%1
4. the "?" at the end of "/Category/%1?" tells the server to throw away the original query string - this might not be desirable, if not: remove the '?'
5. the [R=301] tells the server to redirect using HTTP 301Tested with: http://htaccess.madewithlove.be/
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
-
301 redirect hops from non-https and www
It's best practice to minimize the amount of 301 redirect hops. Ideally only one redirect hop. It's also best practice to 301 redirect (or at least canonical) your non-https and/or your non-www (or www) to the canonical protocol/subdomain. The simplest (and possibly the most common) way to implement canonical protocol/subdomain redirects is through a load balancer or before your app processes the request. Both of which will just blanket 301 to the canonical domain/protocol regardless if the path exists or not In which case, you could have: Two hops. i.e. hop #1 http://example.com/foo to https://example.com/foo, hop #2 https://example.com/foo to https://example.com/bar 301 to a 404. Let's say https://example.com/dog never existed, but somebody for whatever reason linked to it (maybe a typo). If I request https://www.example.com/dog, the load balancer would 301 to a 404 page. Either scenario above should be fairly rare. However, you can't control how people link to you. Should I care about either above scenario? I could have my app attempt to check if the page exists before forwarding, but that code could be complicated.
Intermediate & Advanced SEO | | dsbud0 -
(Urgent) losing traffic after 301 redirect
We face a seo problem of losing traffic after 301 redirect.We have used 301 redirect from a sub-domain url to main domain, after a few month, we discovered that the traffic in google is dropped 40% as well as yahoo dropped 50% without reason, we have updated sitemap already, but we cannot find any reason for the traffic dropped till now..The original url (more then 5000 links)https://app.example.com/ebook Redirected Urlhttps://www.example.com/ebookThank you for your help!
Intermediate & Advanced SEO | | yukung0 -
301 Redirecting from domain to subdomain
We're taking on a redesign of our corporate site on our main domain. We also have a number of well established, product based subdomains. There are a number of content pages that currently live on the corporate site that rank well, and bring in a great deal of traffic, though we are considering placing 301 redirects in place to point that traffic to the appropriate pages on the subdomains. If redirected correctly, can we expect the SEO value of the content pages currently living on the corporate site to transfer to the subdomains, or will we be negatively impacting our SEO by transferring this content from one domain to multiple subdomains?
Intermediate & Advanced SEO | | Chris81980 -
Googlebot being redirected but not users?
Hi, We seem to have a slightly odd issue. We noticed that a number of our location category pages were slipping off 1 page, and onto page 2 in our niche. On inspection, we noticed that our Arizona page had started ranking in place of a number of other location pages - Cali, Idaho, NJ etc. Weirdly, the pages they had replaced were no longer indexed, and would remain so, despite being fetched, tweeted etc. One test was to see when the dropped out pages had been last crawled, or at least cached. When conducting the 'cache:domain.com/category/location' on these pages, we were getting 301 redirected to, you guessed it, the Arizona page. Very odd. However, the dropped out pages were serving 200 OK when run through header checker tools, screaming frog etc. On the face of it, it would seem Googlebot is getting redirected when it is hitting a number of our key location pages, but users are not. Has anyone experienced anything like this? The theming of the pages are quite different in terms of content, meta etc. Thanks.
Intermediate & Advanced SEO | | Sayers0 -
When moving a site from HTTP to HTTPS, will i lose value from the 301 redirect?
I am looking at moving my site from HTTP to full HTTPS, so i will 301 redirect any HTTP requests to their HTTPS counterpart. All my pages in the Google index are HTTP, so will that 301 redirect reduce the value of the pages? Cheers
Intermediate & Advanced SEO | | SEOhmygod0 -
SEO impact of 301 redirects based on IP addresses from a specific state
Hello Moz Community! We are facing an issue that may or may not be unique, but need some advice and/or clarification on the best way to address the issue. We recently rebranded and launched a new site under a new domain and things have been progressing well. However, despite all the up front legwork on trademarks and licensing, we have recently encountered a hiccup that forces us to revert to the old URL/branding for one specific state. This may be a temporary issue that lasts a couple of months or it could potentially be in the court system for a couple of years. One potential solution we have discussed is to redirect the new site to the old site based on IP addresses for the state in question. Looking for any guidance on what type of impact this may have on SEO. Also open to any other suggestions or guidance on dealing with this situation. Thanks
Intermediate & Advanced SEO | | VeteransFirstMarketing0 -
What things should I consider if I am doing a 301 redirect on only 1 page/blog post?
I wrote a blog post on one of my websites and it got picked up by reddit and I got a bunch of nice backlinks and now that website got a nice boost overall, and especially that blog post page. I now wish I would have posted the article on a different website of mine. I would prefer if this other site was getting the traffic and the good backlinks that I've acquired. What are the pros and cons if I move the content over to my other website, and 301 redirect just that one article to the article location on my other website? The blog post I wrote almost instantly began ranking for certain terms in Google. Ideally I would like my other website to rank for those terms, but I realize there will be some differences as search engines look at the website as a whole and take many factors into consideration. I know there are tons of case studies and information about moving entire sites etc but I couldn't find much on this. Any advice, questions or comments would be greatly appreciated. Thanks,
Intermediate & Advanced SEO | | bradbowman
Brad0 -
Questions about 301 Redirects
I have about 10 - 15 URLs that are redirecting to http://www.domainname.comwww.domainname.com/. (which is an invalid URL)The website is on a Joomla platform. Does anyone know how I can fix this? I can't figure out where the problem is coming from.
Intermediate & Advanced SEO | | JohnParker27920