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
-
How to 301 Redirect /page.php to /page, after a RewriteRule has already made /page.php accessible by /page (Getting errors)
A site has its URLs with php extensions, like this: example.com/page.php I used the following rewrite to remove the extension so that the page can now be accessed from example.com/page RewriteCond %{REQUEST_FILENAME}.php -f
Intermediate & Advanced SEO | | rcseo
RewriteRule ^(.*)$ $1.php [L] It works great. I can access it via the example.com/page URL. However, the problem is the page can still be accessed from example.com/page.php. Because I have external links going to the page, I want to 301 redirect example.com/page.php to example.com/page. I've tried this a couple of ways but I get redirect loops or 500 internal server errors. Is there a way to have both? Remove the extension and 301 the .php to no extension? By the way, if it matters, page.php is an actual file in the root directory (not created through another rewrite or URI routing). I'm hoping I can do this, and not just throw a example.com/page canonical tag on the page. Thanks!0 -
301 redirects broken - problems - please help!
Hi, I have a bit of an issue... Around a year ago we launched a new company. This company was launched out of a trading style of another company owned by our parent group (the trading style no longer exists). We used a lot of the content from the old trading style website, carefully mapping page-to-page 301 redirects, using the change of address tool in webmaster tools and generally did a good job of it. The reason I know we did a good job is that although we lost some traffic in the month we rebranded, we didn't lose rankings. We have since gained traffic exponentially and have managed to increase our organic traffic by over 200% over the last year. All well and good. However, a mistake has recently occurred whereby the old trading style website domain was deleted from the server for a period of around 2-3 weeks. It has since been reinstated. Since then, although we haven't lost rankings for the keywords we track I can see in webmaster tools that a number of our pages have been deindexed (around 100+). It has been suggested that we put the old homepage back up, and include a link to the XML sitemap to get Google to recrawl the old URLs and reinstate our 301 redirects. I'm OK with this (up to a point - personally I don't think it's an elegant solution) however I always thought you didn't need a link to the xml sitemap from the website and that the crawlers should just find it? Our current plan is not to put the homepage up exactly as it was (I don't believe this would make good business sense given that the company no longer exists), but to make it live with an explanation that the website has moved to a different domain with a big old button pointing to the new site. I'm wondering if we also need a button to the xml sitemap or not? I know I can put a sitemap link in the robots file, but I wonder if that would be enough for Google to find it? Any insights would be greatly appreciated. Thank you, Amelia
Intermediate & Advanced SEO | | CommT0 -
Moving to a new domain name - 301 redirect NOT an option
Hi everyone My question concerns moving from an old to a new domain name without losing all previous SEO efforts. I am aware that a properly executed 301 redirect is the answer and way to go as well as telling Google about it in Webmaster Tools. However, what is the situation, if you do not own the old domain name anymore? If you have no means of getting back the old domain name and wanting to basically mask/switch the already existing website to the new domain name, will search engines penalise the "new site" as a duplicate, since the "old site" is still in the search engine rankings? I know that not being able to execute a proper 301 redirect and starting out with a new domain means a fresh start, but what is the best way to minimise the negative impact (if any)? Basically dropping the sites' current content and starting out new in favour of the new domain name is not really an option. Even if you were to take the content from the old site and place it on another site, this would surely be seen as duplicate too. Anyone thinks that Webmaster Tools/Google is savvy enough to spot the difference when the "old site" gets removed and the "new one" added instead (in Webmaster Tools). I read something along the lines about having your host point the DNS from the old site to the new one. Could something like be helpful? Thanks all in advance for your help and input!
Intermediate & Advanced SEO | | Hermski0 -
Worpress Redirect
I am migrating a WP site from one domain to another for a client. WP is installed at the root. Typically I would simply issue a 301-redirect for the entire domain, however, in this case, the client wants the content in 2 specific subfolders to remain live on the old site and have everything else redirected. Example: olddomain.com/subfolder-1/ olddomain.com/subfolder-2/ Question: what would the the htaccess code look like to pull this off? Thanks!
Intermediate & Advanced SEO | | SCW0 -
Redirect 301
Hi, I `m redirecting some pages in htaccess The first 15 pages that i redirected it worked. But the last 3 dont work, and i cant figure it out why it is not working. Redirect 301 /analyseverktoy/ /webanalyse
Intermediate & Advanced SEO | | SGacic
Redirect 301 /index.php/ledige-stillinger/ /
Redirect 301 /?page_id=352/ / Anu suggestions?0 -
Undo a 301 redirect
Hi there, 4 months ago I have done a redirect from one domain to another. Now, after about 120 days I have just a few results from the old domain indexed. The problem is that I believe that the old domain name had a really big impact on rankings, as it had the main keyword in the domain name. I'm wondering now if I could restore the old domain just by taking out the 301 instruction and how will search engines react. Do you have any studies on that? Would it be possible? Matt Cutts himself did it with his own domain, but he doesn't talk specifically on the effect of the rankings: http://www.thedotcomblog.com/seo/redirects-after-change-in-domain-name Thanks in advance for any help,
Intermediate & Advanced SEO | | SandraMoZ0 -
How many pages to 301 Redirect
Hi Mozzers, My site has 11,200 pages indexed in Google and I'm looking to remove some of the lesser content which should probably have been picked up by Panda. However these pages work out to about 1,100 in total and I'm not sure whether to remove these bit by bit or just do it in one fell swoop? Does Google not like a site's indexed pages fluctuating too quickly? Are there any other considerations I should be aware of? Thanks!
Intermediate & Advanced SEO | | panini0 -
Does 301 Redirect works on social signals?
Hello, I'm considering strategic change in my site's formation.
Intermediate & Advanced SEO | | BeytzNet
301 redirecting some of the pages is not a problem but the question remains - what will happen with all of my social signals? These pages have Likes, plus ones, and tweets. Thanks0