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
-
Ecommerce catalog update: 301 redirects?
Hello mozers, We run an ecommerce store and are planning a massive catalog update this month. Essentially, 100% of our product listings will be deleted, and an all new catalog will be uploaded. The new catalog contains mostly new products, however there are some products that already existing in the old catalog as well. The new catalog has a bunch of improvements to the product pages, included optimized meta titles and descriptions, multiple language, optimized URLs and more. My question is the following: When we delete the existing catalog, all indexed URLs will return 404 errors. Setting up 301 redirects from old to new products (for products which existing previously) is not feasible given the number of products. Also, many products are simply being remove entirely. So should we go ahead and delete all products, upload the new catalog, update the sitemap, resubmit it for crawling, and live with a bunch of 404 errors until these URLs get dropped from Google? The alternative I see is setting 301 redirects to the home page, but I am not sure this would be correct use of 301 redirects. Thanks for your input.
Intermediate & Advanced SEO | | yacpro130 -
301 redirects aren't passing value.
We recently migrated our shop to a new platform. We are using Wordpress for our main website, but we wanted a separate installation of Wordpress for our shop, so we left the main blog where it was, but moved the shop to a /shop/ sub directory with it's on WP installation. So now we have 2 installations of Wordpress. However, since we've done this, none of the pages on the new shop are ranking for anything. Their page rank is 0, and Moz page authority is 1 for every page on the new site. I've set up the proper 301 redirects, and they're redirecting fine, but none of the page value is coming over. It's been about a week now, and despite re-crawls by google, I'm not seeing any change. Also, one of the original (now re-directed) product pages still has a Page Authority of 13 according to Open Site Explorer. I know it's not high, but it had us ranking in the top 5 for a very important keyword, and now that value is being wasted. For example, one of our product pages that was ranking well was startupfashion.com/product/fashion-brand-line-sheet-template
Intermediate & Advanced SEO | | inkyj
That page is now redirected to
http://startupfashion.com/shop/product/fashion-line-sheet-template I've done 301's plenty of times and I've never seen this issue, so i'm wondering if it could have something to do with having multiple installations of Wordpress. I can't see any obvious issues with it... i have the Yoast SEO plugin configured properly on both installations, and all of the pages ARE being indexed by google. Not sure what is going on. Anyone have any experience with this, or have any ideas? Thanks!!0 -
Geoip redirection, 301 or 302?
Hello all Let me first try to explain what our company does and what it is trying to achieve. Our company has an online store, sells products for 3 different countries, and two languages for each country. Currently we have one site, which is open to all countries, what we are trying to achieve is make 3 different stores for these 3 different countries, so we can have a better control over the prices in each country. We are going to use Geoip to redirect the user to the local store in his country. The suggested new structure is to add sub-folders as following: www.example.com/ca-en
Intermediate & Advanced SEO | | ajarad
www.example.com/ca-fr
www.example.com/us-en
... If a visitor is located outside these 3 countries, then she'll be redirected to the root directory www.example.com/en We can't offer to expand our SEO team to optimize new pages for the local market, it's not the priority for now, the main objective now is to be able to control the prices for different market. so to eliminate the duplicate issue, we'll use canonical tags. Now knowing our objective from the new URL structure, I have two questions: 1- which redirect should we use? 301, 302?
If we choose 301, then which version of the site will get the link juice? (i.e, /ca-en or /us-en?)
if we choose 302, then will the link juice remain in the original links? is it healthy to use 302 for long term redirections? 2- Knowing that Google bots comes from US-IP, does that mean that the other versions of the site won't be crawled (i.e, www.example.com/ca-fr), this is especially important for us as we are using AdWords, and unindexed pages will effect our quality score badly. I'd like to know if you have other account structure in your mind that would be better than this proposed structure. Your help is highly highly appreciated.
Thanks in advance.0 -
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 -
301 redirect and improved ranking
I was wondering if a 301 redirect will improve my ranking. My subpages use to redirect to my homepage ( all the subpages of my site redirecting to my homepage) and my homepage use to have no redirect from non www.to www. ( other than thru google webmaster tools. I am sure why it was like this for my subpages... I was wondering if I can expect some improvements in ranking now that the redirect goes from the none www. to the www version of each subpage and not to the homepage. By the way what was the issue ( was I telling google ) by re-directing all my subpages to the homepage ? was I making google think that my subpages and my homepage were all the same ? was I sending all the link juice from the subpages to my homepage ? etc... Thank you,
Intermediate & Advanced SEO | | seoanalytics0 -
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 -
Redirects 301
Hello guys, I have a doubt. If I reedirect a url with a pagerank of 2 to a new URL, will I loose the PR? My problem is that I have a long url in one page wich is not effective to target a keyword that Im persuing. Im climbing in Google, however I want to 1º place and I dont think that with this long URL I will make it. Advices? Cheers! Pedro M Pereira
Intermediate & Advanced SEO | | PedroM0 -
How do I set up a 301 redirect if the default settings for our web servers create multiple URLs for the same page?
How do I set up a 301 redirect if the default settings for our web servers create multiple URLs for the same page but only views it as one page?
Intermediate & Advanced SEO | | ibex0