Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getting a lot of errors in Webmaster Tools and basically there's a lot of links ending like this: example.com/links.php

How can I redirect these links, to shave off this part at the end? For instance, there is a link in Google:


This should be:


Using .htaccess, how can I redirect from the incorrect links?

share|improve this question

migrated from superuser.com Mar 14 '11 at 17:07

This question came from our site for computer enthusiasts and power users.

The odds are you have lots of HTML errors in your website for those kind of errors to be showing up. You need to fix them, not put a band aid on them. Crawl your site with a tool like Xenu's Link Sleuth and look for where those bad links are and fix them. That will solve your problem with Google and let your users actual find your content as they probably are having a poor user experience right now.

share|improve this answer

As John Conde suggests, you should fix the link that is causing these errors. It is likely a broken link to links.php that looks something like:

<a href="www.example.com/links.php">

which is missing the http:// and should be

<a href="http://www.example.com/links.php">

or if you want to use relative linking:

<a href="/links.php">

However, you also want to do the redirect. The RedirectMatch directive from mod_alias can help. Here is how you strip off everything at the end:

RedirectMatch ^(.*)/www.example.com/.*$ http://www.example.com$1 

Alternately, because the broken link probably points to the links page, you may want to strip off everything at the beginning instead so that broken links work better for visitors:

RedirectMatch ^.*/www.example.com(/.*)$ http://www.example.com$1 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.