mod_rewrite - 将所有不存在的内容发送到index.php
我想让我的 .htaccess 文件重写 index.php 文件中不存在的任何内容。例如: www.example.com/category/subcategory/product1/
将被重写为 index.php?request=category/subcategory/product1
我想执行首先检查该目录是否存在,如果存在,请勿重写。我现在有类似的东西,但只需要知道如何将请求的 URL 获取到 PHP $_GET
变量中:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php [L]
高级感谢您的帮助!
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
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经快完成了:
TBH,实际上没有必要将请求的 URL 放入
$_GET
变量中 - 您始终可以通过$_SERVER['REQUEST_URI']< 访问原始(请求的)URL /code> - 唯一的区别是
REQUEST_URI
始终以前导斜杠开头(例如/category/subcategory/product1
)。You are almost there:
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 thatREQUEST_URI
will always start with leading slash (e.g./category/subcategory/product1
).