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?

1 Answer 1


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]
  • 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/.
    – MrWhite
    May 14, 2013 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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