开发者

mod rewrite rule to convert everything after domain to a get query string

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'].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜