I need some help with rewrite rules in htaccess files. I want everything after the domain, after the first slash to be rewritten to get the query string.
If you take a look at mod rew开发者_Python百科rite everything after domain into get
this is pretty much what I want except that I believe that one of my rules (rewrites files to have a php extension) is interfering with the linked solution.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
What can I do to integrate the linked solution with this rewrite as well?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?query=$1 [L]
English version: If the file or directory does not exist, rewrite to index.php with the query string in $_GET['query'].
For greater flexibility, you could also not pass the request uri into GET with htaccess and just read it directly from $_SERVER['REQUEST_URI'].
精彩评论