问题
First question, here goes nothing...
I'm trying to add a new entry to my .htaccess file (Apache server) with the hopes of translating this URL:
http://platform.localhost/category.all
into this URL:
http://platform.localhost/index.php?page=category.all
The RewriteRule that I'm currently using is this:
RewriteRule ^([^/\.]+)\/?$ index.php?page=$1
This rule has worked fine for all URLs up until now, I can only assume that it is the period that is breaking it.
What I'm trying to achieve is having anything in the URL after the "http://platform.localhost/" passed into the "page" variable of index.php.
I know I've missed something stupid, can someone please be kind enough to point it out?
Cheers
回答1:
the pattern says to reject dots, but you could do tis:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
回答2:
Why not just something like:
RewriteRule index.php - [L]
RewriteRule (.*) index.php?$1
This might fail because I don't remember exactly if querystrings are included when matching against the pattern, so I'm not sure what would result if you'd request:
http://bla.blub/x?q=1
Also note that this is for a .htaccess/directory context.
来源:https://stackoverflow.com/questions/2077304/apache-mod-rewrite-periods-messing-with-pattern