1

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.

1 Answer 1

2

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.

1
  • 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, 2013 at 1:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .