Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

migrated from stackoverflow.com Aug 30 '12 at 11:22

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

1 Answer

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
add comment

Your Answer

 
discard

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.