Server Fault is a question and answer site for system and network administrators. 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'm trying to define a mod rewrite rule which should work like this: contact.php -> index.php?page=contact

my htaccess file has the following content:

RewriteEngine On
RewriteBase /
RewriteRule ^%1$   index.php?page=%1 [L]

unfortunately this gives me a 404. any ideas what's wrong? thanks

share|improve this question

migrated from Aug 30 '12 at 11:22

This question came from our site for professional and enthusiast programmers.

Try this:

RewriteRule ^/([a-zA-Z_-]+)\.php$ index.php?page=$1

This should capture a request for /something.php and then load index.php?page=something. So long as the "something" only conatins lowercase or uppercase letters (a to z), underscores or hyphens. Add or remove characters if you need a different set of rules for what can make up the name of a valid page.

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.