Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Someone has incorrectly linked to some of my urls causing 404 erros in Google Webmaster Tools.

Here is an example

Linked URL:

Correct URL:

I would like to 301 redirect any instance of this kind of incorrect linking to the correct URL. I have tried the following but it generates 404 Errors site wide.

Options +FollowSymLinks
RewriteEngine on    
RewriteRule ^foo-(.*)bar\.html$\.html? [L,R=301]

Could anyone let me know what I am doing wrong?

share|improve this question
up vote 1 down vote accepted

Well, for starters, the regex


will also match "foo-bar.html", which is not good and causes a rewrite loop.

You want this instead:


And in general, the rewriterule should be:

RewriteRule ^/foo-(.+)bar\.html$ /foo-bar.html? [L,R=301]
share|improve this answer

My suggestion is to check the Apache Rewrite log, usually located in /var/logs/apache2. This will tell you what the rewritten result is and may help you identify why this is returning 404's for you.

You may also post the results in your log as this may help us determine the problem.

share|improve this answer
RewriteEngine on
RewriteRule ^foo-(.*)bar\.html$ /foo-bar.html? [L,R=301]
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.