问题描述
我正在编写自己的PHP MVC框架。我的Web服务器已安装到/ public,并创建了一个名为myframework的目录。在此目录下,我有一些子目录,我想将所有请求重定向到myframework / public / index.php,并且我还想拥有请求url。我在myframework目录下创建了.htaccess文件,如下所示:
I am writing my own PHP MVC framework. My web server is installed to /public and i made a directory named myframework. under this directory i have some sub directory and i want to redirect all requests to myframework/public/index.php and also i want to have request url. I made .htaccess file under myframework directory like below:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /myframework/public/index.php?q=$1 [L,QSA]
它适用于除localhost / myframework /之外的所有请求。当此请求到来时,它不执行任何操作。我该如何解决?
It works for all requests but localhost/myframework/. It does nothing when this request is coming. How can i fix it?
推荐答案
此行
RewriteCond %{REQUEST_FILENAME} !-d
表示不重写request指向一个真实目录,这是 localhost / myframework /
所请求的。取出来,您的重写应该开始了。
says not to rewrite when the request points to a real directory, which is what localhost/myframework/
is requesting. Take it out and your rewrite should kick in.
这篇关于使用.htaccess将所有请求重定向到index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!