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 -
How long should I keep the 301 redirect file
We've setup an new site and many pages don't exist anymore (clean up done). But for many of them we have new pages with new url's. We've monitored the 404 and have now many URL's redirected with 301 (apache file). How long should we keep this in place? Checking all links manually to see of new url is in place of the old url (in google) is too much work. tx!
Intermediate & Advanced SEO | | KBC0 -
Is it worth redirecting?
Hello! Is there any wisdom or non-wisdom in taking old websites and blogs that may not be very active, but still get some traffic, and redirecting them to a brand new website? The new website would be in the same industry, but not the same niche as the older websites. Would there be any SEO boost to the new website by doing this? Or would it just hurt the credibility of the new website?
Intermediate & Advanced SEO | | dieselprogrammers0 -
301 redirect w/ dynamic pages to static
I am trying to redirect old dynamically created pages to a new static one (single page). However, when I implement the redirects, it still uses part of the old dynamic url. For instance... dynamic.php?var=example1 dynamic.php?var=example2 dynamic.php?var=example3 should all redirect to: static.html. However, they are redirecting to: static.html?var=example1 static.html?var=example2 static.html?var=example3 The page is resolving fine, but I don't want google to misinterpret the new static page as numerous page with dup content. I tried this in PHP on the dynamic.php page as follows, but it the problem above persisted: header('HTTP/1.1 301 Moved Permanently');
Intermediate & Advanced SEO | | TheDude
header('Location: http://www.mysite.com/static.html'); I tried doing it in my .htaccess file as follows, but the problem persisted: redirect 301 /info/tool_stimulus.php?var=example1 http://www.mysite.com/static.html
redirect 301 /dynamic.php?var=example2 http://www.mysite.com/static.html Can anyone solve this in PHP or w/ htaccess? Help!!! 🙂0 -
301 Redirect to a new domain, Need linkbuilding ideas
Hi, I just 301 redirected my 3 year old domain to a new domain which was created yesterday. Now i want to start link building to my new domain. Should i start slowly by publishing 4-5 articles on article directories and a 1 press release a week? Can someone suggest me some ideas on how to handle a new domain. Will be waiting for replies.
Intermediate & Advanced SEO | | Dex3783783780 -
Confusing 301 / Canonical Redirect Issue - Wizard Needed
I had two pages on my site with identical content. What I did was 301 redirect one page to the other. I also added canonical redirect code to the page that held the 301 code. Here is what I have: www.careersinmusic.com/music-colleges.aspx - this page was a duplicate and I needed it to resolve to:
Intermediate & Advanced SEO | | 4Buck
www.careersinmusic.com/music-schools.aspx Here is the code I used: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX music-colleges.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="music-colleges.aspx.vb" Inherits="music_colleges" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml"> http://www.careersinmusic.com/music-schools.aspx"/> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
music-colleges.aspx.vb
Partial Class music_colleges
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Status = "301 Moved Permanently"
Response.AddHeader("Location", "http://www.careersinmusic.com/music-schools.aspx")
End Sub
End Class XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The problem:
For some reason, when the search “music colleges” is done in Google, I am #7. When the term “music schools” is done, I am around 119. I MUST be getting a penalty for some reason, I just cannot figure the reason. When perform well for one term and terrible for the next? All I can come up with is a duplicate content penalty or something along those lines. Also, music-colleges.aspx seems to still be in Googles index, even though the above 301 happened months ago. Thoughts? site:www.careersinmusic.com/music-colleges.aspx Any insight into this would be GREATLY appreciated. Many Thanks!0 -
Is it ok to redirect
Hello my question is presently we holding one .com for our website and i see in analytics some time people typing .es version of our site too.. which is not registered yet. is it ok to buy that .es extension and do a redirect to our .com version ? thanks
Intermediate & Advanced SEO | | idreams0