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've seen this issue crop up for other people, but in their cases, there was an issue with their regex. A quick trip to regexpal.com indicated to me that this was not the case. I have a simple htaccess file that allows me to write URLs as ".htm" or ".html", rather than ".php". I just recently discovered this script has issues when dealing with query strings ( ?argument=value ). Here's my full .htaccess code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html?\??(.*)$ $1.php?$2 [nc]

When I print the query string of my request, it always comes out empty, and of course a check to array_key_exists doesn't find the id I'm trying to specify. I don't work with Apache much, but I was thinking this would be pretty simple.

If it matters, this htaccess is applied on top of a relatively simple XAMPP setup. I don't think I've even done anything to the httpd.conf file. I can try to provide any other information people think might be relevant.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Simplify This:

RewriteRule ^(.*)\.html?\??(.*)$ $1.php?$2 [nc]

To this:

RewriteRule (.*)\.html?$ $1.php [NC,QSA]

The initial ^ is unnecessary, since .* matches anything already. And preserving the query string manually is (a) problemantic and (b) completely unnessary, since the QSA flag (query string append) will handle all that internally.

share|improve this answer
    
Alright! Simple enough. In my opinion, I still don't see why the original, more manual way didn't work, but I'm just happy to have it working. –  Katana314 Jul 6 '13 at 1:53

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.