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

I'm using HTML5 BP's .htaccess file unedited. Everything works fine until I add my own rewrite rule:

Options +FollowSymlinks

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+-?[a-z]+)/$ /$1.php

this works fine if add it to it's own .htaccess file (after starting the engine and adding options) but does not when added to the html5 BP's file . I've tried placing it all over the document, inside the if tags, top of the doc and bottom.

I'd like the rewrite to load when a user inputs .

share|improve this question
up vote 0 down vote accepted

That expression won't match /example:

You've got the / on the end, not the beginning as you have in your replacement string. Given that it's in .htaccess, and assuming that example.php is in the same directory as this .htaccess file, then you don't want slashes at all. Clarify if this is not the case. And if you have access to the server config, then don't use .htaccess, period.

You've got the - as optional, but then you're forcing another one-or-more match of alphabetical characters, and you're forcing lower-case. This is far more complicated than it needs to be; how about this:

RewriteRule ^([\w-]+)$ $1.php
share|improve this answer
Sorry I missed typed how it should work . I want when a user inputs then apache will load . I really want to use this for a blog system where the variable will be placed in the url variables . – Frank Astin Jan 23 '12 at 19:42
@FrankAstin The rule that I've provided above will rewrite /example to /example.php, assuming that the .htaccess file is located directly in the DocumentRoot. – Shane Madden Jan 23 '12 at 19:51
Yeah it's in the root : Just tried it without the html5BP and it works as expected . So it's definitely something to do with placement in the H5BP htaccess ... – Frank Astin Jan 23 '12 at 21:03
@FrankAstin Well, with a quick glance at that file I'm not seeing anything that should conflict.. but, try putting your rules immediately under the RewriteEngine On line in that file, and add a [L] to the end of the RewriteRule line. – Shane Madden Jan 23 '12 at 21:30

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.