Webmasters Stack Exchange is a question and answer site for pro webmasters. 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

Using this .htaccess file:

Options +FollowSymLinks 
Options +Indexes 
RewriteEngine On 

RewriteRule matches/(.*)-v-(.*) matches/matchevent.php?event=$1%20v%20$2 [R=301,L]

This url: http://www.example.com/sport/league/matches/team1-v-team2

rewrites to: http://www.example.com/sport/league/matches/matchevent.php?event=team1%20v%20team2

However, the browser returns this:

Not Found
The requested URL www.example.com/sport/league/matches/team1-v-team2 was not found on this server.

The .htaccess file is inside the matches directory where matchevent.php is. I have also tried it in the league directory.

Could someone help me?

share|improve this question

I replicated your setup. There are two problems:

  1. I can't get the %20 in the rewrite URL to work. I can get the rule to work if I replace %20 with +. A plus sign should URL decode to a space the same way a %20 does, so it should be treated the same in your matchevent.php script.
  2. It was redirecting me to a bad relative path. If I change the redirect path to start from the root with /sport/league/matches/, it works fine.

Here is the rewrite rule that works for me:

RewriteRule matches/(.*)-v-(.*) /sport/league/matches/matchevent.php?event=$1+v+$2 [R=301,L]

I think you will want to remove the R=301 from the rewrite rule so that it doesn't do a redirect, but rather shows you the content at the pretty url:

RewriteRule matches/(.*)-v-(.*) /sport/league/matches/matchevent.php?event=$1+v+$2 [L]
share|improve this answer
Alternatively, spaces in the substitution can be backslash escaped \ , or even enclose the whole substitution string in double quotes. In the question, relative paths are used in the substitution (although you've changed it to a root-relative path, which also gets around the problem) in which case RewriteBase is probably required in order to correct the URL prefix. eg. RewriteBase /sport/league/. – w3dk May 14 '13 at 14:02

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.