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 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 mydomain.com/example.php when a user inputs mydomain.com/example .

share|improve this question
add comment

1 Answer

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 mydomain.com/example then apache will load mydomain.com/example.php . 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
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.