301 Redirect using rewrite rule in .htaccess
-
Hi guys,
I have these types of URLs with the format below that are seen as duplicate contents
http://www.mysite.com/index.php?a=11&b=15&d=3&c=1
I wanted to permanently redirect them to my homepage. I am thinking if this is possible in .htaccess using rewrite conditions?
Thanks in advance...
-
This is a solutions, but its an ugly one, does anyone really wants a home url of http://www.mysite.com/index.php?a=11&b=16&c=5&d=1&page=2. you then have the problem of people linking to that page.
I believe michael said in a previous post that they were prodused by his CMS, the best idea would be to get rid of them rather then deal wioth them if posible.
-
From memory, I believe Michael has these urls produced by his CMS and are unnecessary, i could be getting him mixed up with someone else.
also doing this in Google does not help other search engines, you would need to do it in all search engines for all possible combinations for each pages, this can become un-manageable. -
I have to say I agree with Sha on this one.
If you are not confident in using .htaccess then I wouldn't bother. I think there is a much easier solution:
1- As Sha said, use webmaster tools to tell Google how to handle these parameters, this should slowly start to take them out of the index.
2- Add rel=canonical to all your pages, this way even if parameters are added, the rel=canonical will always point back to the original and remove any risk of duplicate content.
I hope this helps.
Craig
-
Hi Michael,
You do not need to make any changes to your .htaccess file. Actually, if you 301 these URLs you will break your search so that it no longer works.
The solution I would use is to go into Google Webmaster Tools and tell Googlebot to ignore the parameters you are concerned about.
In your code, the ? says "here come some parameters" and the & separates those parameters. So, in the case you have quoted, the parameters are a, b, c, d.
Be aware of course, that Roger will still see these URLs as duplicates since he doesn't know about your private conversations with Google This means that they will still appear in your SEOmoz report, but as long as you make a note of them so you know they can be ignored that shouldn't be a problem.
Hope that helps,
Sha
-
I disagree more with the level of apprehension, rather than the premise itself. Anyhow I’m off to bed.
-
Alan, we will just have to disagree on this topic.
I too have studied Computer Science in college. I too have a wall filled with MS certifications. I too have been programming since before the internet and even before hard drives existed. I am only 40 but the first PC I used was an Atari 800 and the command to save my work was "csave" which stood for "cassette save". This was before even floppy disks were popular and data was saved to cassette tapes.
I certainly am not forbidding anyone from taking whatever action they deem fit. It is indeed up to Michael or any reader to assess what changes they are comfortable making for their site.
The point I am making is many people grow very comfortable in making changes to their website, especially SEO-related changes. It is relatively safe to do such. If you make a mistake, your site may not rank as well, may not load as fast, may not appear correctly in all browsers and so forth. The consequences are relatively low.
Making changes in an htaccess file is a completely different ballgame. One character out of place and your site can instantly be taken off line. If that happened, it's actually not so bad compared to other problems which can be created. A character out of place can disable your site security and the person making the change would likely not realize the problem until their site was hacked. A character out of place can cause other functionality of your site to not work correctly. It can also cause the fix being implemented to work in some but not all instances.
I highly encourage users to make most changes to their sites according to their comfort level. Htaccess modifications is a clear exception. A user can easily be mislead to believe their site is working fine only to later realize there is a major problem with the site. There are countless instances where a site was exploited due to a vulnerability in the htaccess file. I therefore strongly recommend for users never to touch their htaccess file unless they are extremely confident in the changes they are making. Many websites will offer code snippets which can provide users a false sense of security and lead them to experiment. It is a bad idea to do such with the htaccess file.
-
I have
been programming since before the internet came to be, I have studied Computer
Science at University and passed numerous Microsoft Certifications, and while I
would not discount study, it is my experience that I have never met a great
programmer that did not learn by trail and error, after all this is how you
become experienced. There is no danger in using a backup, RegEx does not work
sometimes and not others, it is not dynamic, it is a static peace of code. You
will not excel at SEO unless you learn these things. I am sure Michael is capable
of deciding if he wants to do it himself, he seems to have got a long way already.
It would seem to me he is learning quite quickly. You may suggest that you
would not try, but I don’t think it is correct to forbid others. -
I'm sorry but the idea of advising users without expertise to modify their htaccess file is completely reckless. The trial & error approach can easily lead to circumstances where the rule works some of the time but not always. Worse, it can negatively impact other rules and site security causing major problems.
Without knowing the details of the site involved, I tend to make the safe assumption the site is important and there are one or more people who's livelihoods depend on the site. Having worked with clients who have recovered from the damage caused by errors in htaccess files I will firmly share my experience that no one other then a qualified expert should ever touch the file. The potential for damage is very high.
-
All he needs to do is keep a back up, and he can have as many tries as he wants. He simpley has to replace the file with his back up if he goes wrong.
There is little danger here. -
htaccess rewrite rules are based on Regex expressions. Your current Regex rewrite rules can be modified to adjust for the specific URLs. You need to locate an experienced programmer to write the expressions for you.
-
Hi Mchael.
Yes, you can use htaccess to rewrite or redirect the URL.
Where do these URLs presently lead to? If these URLs are duplicates for pages on your site, I would suggest using a 301 redirect to send the traffic to the proper URL rather then your home page.
If your server uses cPanel, there is a Redirect tool you can use. This tool makes the process of adding a redirect easier and safer then modifying your htaccess file. Your htaccess file controls various aspects of your site's security, accessibility and SEO. The slightest error can cause your site to instantly be inaccessible. I would not recommend making any changes to your htaccess file except by an experienced programmer. Even using the correct code in the wrong order can lead to problems.
-
I work on microsoft servers, i dont use .htaccess
but this is the rule i woudl write to fix all urls stating with index.php, no mater what the querystreing
<rule name="DefaultRule" stopprocessing="true"><match url="^index.php"><action type="Redirect" url="/" appendquerystring="false"></action></match></rule>
but try this let me know if it works i have a few other ideas
RewriteRule ^/index.php / [R=301,L]
-
Hi Alan,
I think it's now clear to me that they should be rewritten. Thanks for pointing me to the right direction.
I have a classified site and in my .htaccess I have these rewrite rules by default
RewriteRule ^/?(new)/(1_day)/([0-9]+)/([^./\"'?#]+).html$ index.php?a=11&b=$3&c=65&d=4 [L] ##category newest 1day
RewriteRule ^/?(new)/(1_week)/([0-9]+)/([^./\"'?#]+).html$ index.php?a=11&b=$3&c=65&d=1 [L] ##category newest 1week
RewriteRule ^/?(new)/(2_weeks)/([0-9]+)/([^./\"'?#]+).html$ index.php?a=11&b=$3&c=65&d=2 [L] ##category newest 2weeks
RewriteRule ^/?(new)/(3_weeks)/([0-9]+)/([^./\"'?#]+).html$ index.php?a=11&b=$3&c=65&d=3 [L] ##category newest 3weeksRewriteRule ^/?(new)/(1_day)/([0-9]+)/([^./\"'?#]+)/([0-9]+).html$ index.php?a=11&b=$3&c=65&d=4&page=$5 [L] ##category newest 1day pages
RewriteRule ^/?(new)/(1_week)/([0-9]+)/([^./\"'?#]+)/([0-9]+).html$ index.php?a=11&b=$3&c=65&d=1&page=$5 [L] ##category newest 1week pages
RewriteRule ^/?(new)/(2_weeks)/([0-9]+)/([^./\"'?#]+)/([0-9]+).html$ index.php?a=11&b=$3&c=65&d=2&page=$5 [L] ##category newest 2weeks pages
RewriteRule ^/?(new)/(3_weeks)/([0-9]+)/([^./\"'?#]+)/([0-9]+).html$ index.php?a=11&b=$3&c=65&d=3&page=$5 [L] ##category newest 3weeks pagesunfortunately, these rules could not handle all URLs of the same format with different variables like the following below
http://www.mysite.com/index.php?a=11&b=15&d=3&c=1
http://www.mysite.com/index.php?a=11&b=15&d=3&c=2
http://www.mysite.com/index.php?a=11&b=16&c=5&d=1
http://www.mysite.com/index.php?a=11&b=16&c=5&d=1&page=2
http://www.mysite.com/index.php?a=11&c=5&d=1&b=230
Any idea on how I can solve this problem to avoid duplicate content?
Thanks in advance...
-
rewrite and redirect are not the same thing. you want to 301 them, but better still why do you have them?
Do you have a wordpress site?If these errores were found by a crawler it means that you have the links on your site somewhere. the best thing to do is correct the links. 301's leak link juice you want to limit their number.
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 Can I Redirect an Old Domain to Our New Domain in .htaccess?
There is an old version of http://chesapeakeregional.com still floating around the web here: http://www.dev3.com.php53-24.dfw1-2.websitetestlink.com/component/content/category/20-our-services. Various iterations of this domain pop up when I do certain site:searches and for some queries as well (such as "Diagnostic Center of Chesapeake"). About 3 months ago the websitetestlink site had files and a fully functional navigation but now it mostly returns 404 or 500 errors. I'd like to redirect the site to our newer site, but don't believe I can do that in chesapeakeregional.com's .htaccess file. Is that so and would I need access to the websitetestlink .htaccess to forward the domain? Note* I (nor anyone else in our organization) has the login for the old site. The new site went live about 9 months before I arrived at the organization and I've been slowly putting the pieces together since arriving.
Intermediate & Advanced SEO | | smpomoryCRH0 -
Can I undo 301 redirects to purchase site
A website I am thinking of buying has 301 redirected all pages on his site to one page that explains the site is closing down. If I tell him to change the 301 to 302s will I be able to recover the old pages on the site and keep the authority, rankings and link power of the old pages and not the "Closing page"? Is all i have to do is undo the 301 redirects and everything will go back to how the site was before the 301s were in place? Or will I lose all the link power on individual pages because they already transferred to the "Closing page"? Thanks!
Intermediate & Advanced SEO | | atomiconline0 -
Handling Multiple Domain 301 Redirects on Single htaccess file
Hello, I have a client that currently that has 9 different markets with different sub-domains on one server (aka one htaccess file.). All the sites have very similar Navigation and some of them contain the same products aka same URLs. The site is using Magento CMS and I'm trying to figure out how to redirect some products that have been removed from one of the stores. The problem I'm running into is when I try to redirect one store url, it redirects all the site's URLs. Example http://store.domain1.com/ http://store.domain2.com/ I'd like to redirect http://store.domain1.com/old-url.html to http://store.domain1.com/new-url.html without making http://store.domain2.com/old-url.html redirect. I've literally been pulling out my hair trying to figure this one out but have had no luck. Does anybody have any ideas on how I could do this without having the sites redirect or create any loops? Any wisdom from you apache experts would be greatly appreciated. Thanks, Erik
Intermediate & Advanced SEO | | Erik-M0 -
What things should I consider if I am doing a 301 redirect on only 1 page/blog post?
I wrote a blog post on one of my websites and it got picked up by reddit and I got a bunch of nice backlinks and now that website got a nice boost overall, and especially that blog post page. I now wish I would have posted the article on a different website of mine. I would prefer if this other site was getting the traffic and the good backlinks that I've acquired. What are the pros and cons if I move the content over to my other website, and 301 redirect just that one article to the article location on my other website? The blog post I wrote almost instantly began ranking for certain terms in Google. Ideally I would like my other website to rank for those terms, but I realize there will be some differences as search engines look at the website as a whole and take many factors into consideration. I know there are tons of case studies and information about moving entire sites etc but I couldn't find much on this. Any advice, questions or comments would be greatly appreciated. Thanks,
Intermediate & Advanced SEO | | bradbowman
Brad0 -
DNS or 301 Website Redirect
We are running a marketplace site, so we have thousands of vendors selling their products on our site. Each vendor has a Profile page and we are soon to launch a premium store-front that is white label. Many of these vendors will want to point a custom url to their premium store-front (which is a sub domain of the marketplace) and we are trying to get an understanding of how we should instruct them to point their url in a way that will give the main marketplace site the seo juice. We also want to understand what will show up in the address bar. Will it be their url or our sub domain? Will any of the marketplace seo juice boost their url local listing status?
Intermediate & Advanced SEO | | bloomnation0 -
Previously ranking #1 in google, web page has 301 / url rewrite, indexed but now showing for keyword search?
Two web pages on my website, previously ranked well in google, consistent top 3 places for 6months+, but when the site was modified, these two pages previously ending .php had the page names changed to the keyword to further improve (or so I thought). Since then the page doesn't rank at all for that search term in google. I used google webmaster tools to remove the previous page from Cache and search results, re submitted a sitemap, and where possible fixed links to the new page from other sites. On previous advice to fix I purchased links, web directories, social and articles etc to the new page but so far nothing... Its been almost 5 months and its very frustrating as these two pages previously ranked well and as a landing page ended in conversions. This problem is only appearing in google. The pages still rank well in Bing and Yahoo. Google has got the page indexed if I do a search by the url, but the page never shows under any search term it should, despite being heavily optimised for certain terms. I've spoke to my developers and they are stumped also, they've now added this text to the effected page(s) to see if this helps. Header("HTTP/1.1 301 Moved Permanently");
Intermediate & Advanced SEO | | seanclc
$newurl=SITE_URL.$seo;
Header("Location:$newurl"); Can Google still index a web page but refuse to show it in search results? All other pages on my site rank well, just these two that were once called something different has caused issues? Any advice? Any ideas, Have I missed something? Im at a loss...0 -
Redirecting, then redirecting back
Hey, mozzers! My first question ever... I have a client who has (fictitionally) WickerPatioHomeStore.com, which features wicker home decor. Not too long ago, they wanted a shorter, easier URL, so they redirected to another domain they own, WickerPatio.com (again, fictional). They saw somewhat of a drop in traffic, and wonder if there's a correlation with the words "home store" not being in their domain any more. When considering the two, I figure that relevant factors would be age of domains, history of content of the domains, and inbound links to each domain. Any thoughts on other things to consider? Thanks very much!! ~ Scott
Intermediate & Advanced SEO | | GRIP-SEO0 -
Choose of destination for a 301 redirection
Hi, I had a website paris-football.com which ranked quite well on specific request as 'paris football" and "paris foot". I decided 2 months ago to stop this website as I had no time to update it and it was quite rubish in terms of content and make a redirection to a better quality website. I decided to redirect to the deep url http://www.sportytrader.com/paris-foot.php . The destination Url has not beneft from the redirection and has even seen its rankings drop since the redirection. do you think that it would have been better to redirect to the Home Page http://www.sportytrader.com ? Do you think that I can still change the destination url ? Thanks a lot for your help,
Intermediate & Advanced SEO | | jarnac0