Cannot match literal dot with htaccess regex
The problem: I cannot figure out how to match a literal dot in my expression so I could rewrit开发者_开发知识库e query strings containing dots. First I tried something like this:
RewriteRule ^([\.\w]+)$ index.php?url=$1 [L]
I have a php script:
echo "url is: ".$_GET['url'];
which should, in theory, output anything that I write in my query. But for any query containing only letters and dots, my script always outputs:
url is: index.php
I've tried these expressions as well:
^(.+)$
^([.\w]+)$
And the result is the same.
So the question is: are my expressions wrong or does this have something to do with server's config?
It looks like there is another request which is processed before the rule is applied, if I use a rule which matches less than index.php
(e.g. ..
for matching xy
), the result is as expected: xy
. With more relaxing rules like .*
or .+
it fails. x.*
works fine however.
You can add another condition to ignore requests like index.php
:
RewriteCond %{REQUEST_FILENAME} !index\.php$
RewriteRule ^(.+)$ index.php?url=$1 [L]
This was tested/ debugged with:
<?php
printf("url is: %s <br>\n", htmlspecialchars(filter_input(INPUT_GET, 'url')));
echo "<pre>",htmlentities(print_R($_SERVER, 1));
精彩评论