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
-
Recovering from an open redirect
From a previous company we have inherited a domain which once contained an open redirect redirect.magnet.me. Even though this domain has been returning a 410 for every single request directed at it for the last few months, we continue to see new links popping up in Google which refer to this domain https://www.google.com/search?safe=off&q=%22redirect.magnet.me%22 Currently we just keep disavowing these links, but at the same time they keep appearing in our Moz.com tooling, being unable to disavow those links here. Does anybody have any successful tips how to deal with this scenario, compared to only disavow new links after the fact?
Intermediate & Advanced SEO | | rogier_slag0 -
Possible issues with 301 redirecting to a new domain name
Ive got a current domain and after a bit of a rebrand Im considering 301 rediecting the current site to a newly purchased domain. Id redirect each age to idential pages. Am I likely to see any issues. I know this is the recomended way from Google but just wondering how smoothly it works and whether Im likely to see any ranking drops or other problems?
Intermediate & Advanced SEO | | paulfoz16090 -
Home page url 301 redirect suggestion
Hello, In our site we have already done 301 redirect from http:// to http://www. However, the home page links are still coming in 2 ways http://www.mycarhelpline.com/ http://www.mycarhelpline.com/index.php?option=com_newcar&view=search&Itemid=2 Need suggestion We have already use rel canonical is another 301 redirect to be used for maintaining the home page pr from seo point of view. Does google still takes both urls as separate url and finds duplicate content
Intermediate & Advanced SEO | | Modi0 -
Effect of 301 redirect to a relative url to homepage?
One of our new clients recently encountered a site-wide ranking drop for many keywords and I'm pretty confident regarding their link profile as to being 98% legit. Background: 1. Client full site is https, and all http pages are 301 redirected to their https counterpart 2. Client has ~50 links partners (all legitimate sites + schools etc) links to client with urls such as www.example.com/portal/123.aspx that redirects to www.example.com. 3. Client homepage 301 redirects from www.example.com to www.example.com/default.aspx and then 301 redirects to the relative url "/Home.aspx". 4. Client launched some testing with Google website optimizer tool. ~1-2 months ago. Symptoms: 1. Rankings dropped for basically many/all 30-40+ keywords by ~15 positions 2. Seomoz reports close to a double of existing pages + (600+) duplicate content in the same date range. Webmasters only report 80 duplicate titles though. 3. Domain authority by seomoz reduced a bit + backlinks recorded by seomoz to the website nearly halved in the past 2 months. I'm not sure if I narrowed this towards the right direction, and it isn't clear when the relative url 301 redirect was implemented: 1. The 301 redirect to the relative page (www.example.com/default.aspx to "/home.aspx") is accounting for the loss of links recorded by seomoz. 2. The ~50 links the client currently use (www.example.com/portal.123.aspx 301 redirecting to www.example.com, also relative) as a tracking tool is being considered 301 redirect abuse. 3. Maybe something went wrong with the usage of google optimizer tool for SEO purposes? Visitor traffic to each of the tested pages looked fine. I would greatly appreciate any advice/insights on what I might be missing in terms of direction / factors. Thanks! Alex
Intermediate & Advanced SEO | | sixspokemedia0 -
New to SEO. How do I set up a 301 Redirect? What Else should I do?
Hello, I am new to web design. I designed my own site using dreamweaver and did all my seo on my own, I read a few books. Long story short I rank on the bottom of page 1 just after 3 months and the keywords are highly competitive. Now, I am up against some heavy hitters from national brands versus my local real estate site. I don't have a 301 redirect, and am not sure what else I should be doing to get my site ranked higher. I have back links from various sites, ( non-paid ) so it's what others call white hat. When I grade my site on website grader I get a great score versus the sites that are higher than me. I'm guessing my sites age is an issue. I guess I'm looking for some guidance. Thank you all, Here is my site to view. http://www.bronxpad.com
Intermediate & Advanced SEO | | bronxpad0 -
My site penalized after 301 Redirect or redesign?
Hi, I have a question regarding my site (http://www.pokeronlineitalia.com) that has, all of a sudden, lost rankings on several keywords; plus, Google Analytics and the plug-in Clicky installed on my site (the site is built on WordPress) claim that my site has no visitors/visits anymore. I would like to provide a little background of what has happened. Three weeks ago I asked my web hosting company to do a 301 redirect from http://pokeronlineitalia.com to http://www.pokeronlineitalia.com. At the same time I asked a web hosting company to to a redesign of the site. Strangely, the day after the new redesigned site went online Google Analytics and the Clicky plug-in showed that my site, from one day to the other, had no visitors/visits anymore (I had installed Google Analytics and Clicky before the 301 redirect). In addition, I noticed that I had lost positions on many keywords for which I used to rank on the second page. However, the PR of the site has remained intact and Google is indexing it without problems. Plus, I still rank high for a keyword. I tend to believe that because of this, my site was not penalized by mighty Google...but I'd like an SEO expert to tell me what he thinks about it. In particular, please answer this: has my site lost rankings because of the 301 redirect? Has my site been penalized because of the redesign? Is this only a temporary situation? Thank you very much for your help. Sal
Intermediate & Advanced SEO | | salvyy0 -
.htaccess - error404 redirect within a directory?
Hi, One of my clients has a CMS website offering Health and Safety training. When the courses have been run they automatically drop off of the system which is great for the front-end of the site but this leaves pile 404 errors for the URLs. I am trying to put a .htaccess redirect in place that will redirect back to the main category for that course i/e : http://www.domain.co.uk/courses/highways/6-NRSWA/27-nrswa-operative-sept-11.html will redirect to http://www.domain.co.uk/courses/highways/6-NRSWA I have spent a looooong time hitting google for a solution but can't seem to come up with anything. If at all possible I would also like to be able to post a php variable via the redirect url so that I can display a message on the category page saying that the course is no longer available be please select a different course. i/e: http://www.domain.co.uk/courses/highways/6-NRSWA?course=not-available Any help on this would be most gratefully received.
Intermediate & Advanced SEO | | AdeLewis0 -
Htaccess funny characters
Hi Panda update,tickled, slapped and then punched us. I'm now weeding through crawl errors, one of them is http://www.flasharcadegamessite.com/26226-paper-airplane-flight.html">paper airplane flight I tried 301 this to it's proper page using Redirect 301 /26226-paper-airplane-flight.html">paper airplane flight http://www.flasharcadegamessite.com/26226-paper-airplane-flight.html but the server starts spitting out 500 errors. How does one add that rule into htaccess ? thanks
Intermediate & Advanced SEO | | Flapjack0