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
-
Can anyone please explain the real difference between backlinks, 301 links, and redirect links?which one is better to rank a website? i am looking for the help for one of my website
Can anyone please explain the real difference between backlinks, 301 links, and redirect links? which one is better to rank a website? I am looking for help for one of my website vacuum cleaners
Intermediate & Advanced SEO | | hshajjajsjsj3880 -
301 Redirect in breadcrumb. How bad is it?
Hi all, How bad is it to have a link in the breadcrumb that 301 redirects? We had to create some hidden category pages in our ecommerce platform bigcommerce to create a display on our category pages in a certain format. Though whilst the category page was set to not visable in bigcommerce admin the URL still showed in the live site bread crumb. SO, we set a 301 redirect on it so it didnt produce a 404. However we have lost a lot of SEO ground the past few months. could this be why? is it bad to have a 301 redirect in the breadrcrumb.
Intermediate & Advanced SEO | | oceanstorm0 -
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 -
Technical 301 question
Howdy all, this has been bugging me for a while and I wanted to know the communities ideas on this. We have a .com website which has a little domain authority and is growing steadily. We are a UK business (but have a US office which we will be adapting too soon) We are ranking better within google.com than we do on google.co.uk probably down to our TLD. Is it a wise idea to 301 our .com to .co.uk for en-gb enquiries only? Is there any evidence that this will help improve our position? will all the link juice passed from 301s go to our .co.uk only if we are still applying the use of .com in the US? Many thanks and hope this isn't too complicated! Best wishes,
Intermediate & Advanced SEO | | TVFurniture
Chris0 -
Is it ok to 301 redirect this previously algorithmicly penalised site?
Hi All, Is it OK to 301 redirect site A to site B? Site A: http://goo.gl/P9Zp2y Site B: http://goo.gl/ySDCzb The story - in 2013 site a seemed to be penalised with some kind of anchor text algorithm penalty - SEO couldnt fix, so created site B and turned site A into a holding page with a no follow link to new site. SEO company worked on disavow file etc, implemented in late 2013 301 redirect site A to B in late 2013 - SEO advised to stop 301 about 8 weeks later... This was my fault i didnt realise the implications of a redirect... Stopped the redirect, but too late, as site B dropped in rankings in early 2014 - new disavow files uploaded to both sites, but damage seems done now. No longer have a SEO company, and i would ideally like to 301 redirect site A to B, as it looks messy having a holding page - but wanted to check if SEO would still strongly advise against that? please advise James
Intermediate & Advanced SEO | | isntworkdull0 -
(Australia) Changing .net.au to .com.au - web dev is refusing to do a 301 redirect and wants to run two sites?
After years using a .net.au site, my client has purchased the .com.au version of the same domain. I've now set up a new, responsive website using a wordpress template with new content, but used a similar page structure. I've asked their web developer to now do a 301 permanent redirect on each old page from .net.au site to it's new .com.au page, but he has refused, saying it would be bad for long term SEO. Instead, he says they should run both sites (which I thought would cause duplicate content issues). Both domains are hosted with the same company. I thought as long as the 301 redirects were done on a page by page basis, there were no issues? I'm no SEO expert, (which he claims to be), so I just wanted to get another opinion on what best practice would be in this instance.
Intermediate & Advanced SEO | | carolineraad0 -
Handling 301 Redirects when Moving from IIS to Apache Linux
I am moving a blog from domain A on IIS to domain B on Linux. Same posts and pages - different domain. I'm looking for a guide, article or steps on what needs to be done on the IIS side to make sure we do this correctly. Thanks !
Intermediate & Advanced SEO | | GlennFerrell0 -
How To 301 Redirect .html pages
I need to redirect a page/URL that is purely .html to a new location. I don't know how to do this. All the redirects I can find are for server side code pages .php/.aspx etc. From my understanding I can't put a server side redirect in a .html file. I am hosting on a microsoft server, however the new page I am redirecting to is .php. I am running some WordPress (.php) files on the server. I need to make it redirect before the old page loads so visitors don't start reading something that is about to get redirected Can someone please help me?
Intermediate & Advanced SEO | | MyNet0