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?


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.


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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy