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
-
Wrong redirect used
Hi Folks,
Intermediate & Advanced SEO | | Patrick_556
I have a query & looking for some opinions. Our site migrated to https://
Somewhere along the line between the developer & hosting provided 302 redirect was implemented instead of the recommended 301 (the 301 rule was not being honured in the htaccess file.)
1 week passed, I noticed some of our key phrases disappear from the serps 😞 When investigated, I noticed this the incorrect redirect was implemented. The correct 301 redirect has now been implemented & functioning correctly. I have created a new https property in webmaster tools, Submitted the sitemap, Provided link in the robots.txt file to the https sitemap Canonical tags set to correct https. My gut feeling is that Google will take some time to realise the problem & take some time to update the search results we lost. Has anyone experienced this before or have any further thoughts on how to rectify asap.0 -
301 redirect to search results page?
Hi - we just launched our redesigned website. On the previous site, we had multiple .html pages that contained links to supporting pdf documentation. On this new site, we no longer have those .html landing pages containing the links. The question came up, should we do a search on our site to gather a single link that contains all pdf links from the previous site, and set up a redirect? It's my understanding that you wouldn't want google to index a search results page on your website. Example: old site had the link http://www.oldsite.com/technical-documents.html new site, to see those same links would be like: http://www.newsite.com/resources/search?View+Results=&f[]=categories%3A196
Intermediate & Advanced SEO | | Jenny10 -
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 -
Multiple 301 Redirect Query
Hello all, I have 2 301 redirects on my some of my landing pages and wondering if this will cause me serious issues. I first did 301 directs across the whole website as we redid our url structure a couple of months ago. We also has location specific landing pages on our categories but due to thin/duplicate content , we have got rid of these by doing 301's back to the main category pages. We do have physical branches at these locations but given that we didnt get much traffic for those specific categories at those locations and the fact that we cannot write thousands of pages of unique content content , we did 301's. Is this going to cause me issues. I would have thought that 301's drop out of serps ? so is this is an issue than it would only be a temporary one ?.. Or should I have 404'd the location category pages instead. Any advice greatly appreciated. thanks Peter
Intermediate & Advanced SEO | | PeteC120 -
301 Redirection and apostrophes in URLs
Hi I am experiencing trouble getting any redirects with apostrophes in the URLs to 301 redirect in order to eliminate 404 errors. I have tried replacing the instance of the apostrophe in the source URL field to %27 and variations of this but to no avail. The site is a wordpress site (the old URLS are legacies from the old Business Catalyst site) and I am using the redirection plug in. I have gone into some detail with a helpful soul here http://wordpress.org/support/topic/how-to-deal-with-apostrophes-in-source-url but unfortunately to no result. If anyone has any idea how to solve this puzzle I would be grateful for the help. Example: http://www.tesselaars.com/blog/Inside_Flowers/post/Online_Marketing_for_Florists_Part_1%E2%80%93_A_Website_You_Won%27t_Regret/
Intermediate & Advanced SEO | | Seamoose0 -
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 -
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 -
301 redirect
Hi there, I have some good links pointing to one of my web pages at the moment, however we are just about to launch a new design with new URL structure and I am clear that I need to do a 301 redirect on the URL to the new URL. However, do I keep the old URL live forever? or can I remove it after a while? Kind Regards
Intermediate & Advanced SEO | | Paul780