mod_rewrite的 - 发送一个不存在的index.php一切不存在、mod_rewrite、php、index

2023-09-02 00:38:28 作者:不爱就滚,老娘不稀罕

我想有我的.htaccess文件重写一个不存在的index.php文件什么。因此,例如: www.example.com/category/subcategory/product1 / 将被改写成的index.php请求=类别/子/产品1?

I would like to have my .htaccess file rewrite anything that doesn't exist to the index.php file. So for example: www.example.com/category/subcategory/product1/ would be rewritten to index.php?request=category/subcategory/product1

我要进行检查,看是否该目录存在一个内核,如果确实如此,不重写。我有这样的事情,此刻,而且只需要知道我如何能得到请求的URL到PHP $ _ GET 变量:

I want to perform a check to see if the directory exists first though, and if it does, do not rewrite. I have something like this at the moment, but just need to know how I can get the requested URL into the PHP $_GET variable:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php [L]

任何帮助高级感谢!

Advanced thanks for any help!

推荐答案

您几乎有:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]

TBH,没有真正必要把请求的URL为 $ _ GET 变量 - 你可以随时通过访问原始的(要求)网址 $ _ SERVER ['REQUEST_URI'] - 唯一的区别是, REQUEST_URI 将总是以斜线(如 /类别/子/产品1 )。

TBH, there is no real need to put requested URL into $_GET variable -- you can ALWAYS access original (requested) URL via $_SERVER['REQUEST_URI'] -- the only difference is that REQUEST_URI will always start with leading slash (e.g. /category/subcategory/product1).

 
精彩推荐