简体   繁体   English

使用.htaccess将所有请求重定向到index.php

[英]Redirect all requests to index.php using .htaccess

I am writing my own PHP MVC framework. 我正在编写自己的PHP MVC框架。 My web server is installed to /public and i made a directory named myframework. 我的Web服务器已安装到/ public,并创建了一个名为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. 在此目录下,我有一些子目录,我想将所有请求重定向到myframework / public / index.php,并且我还想拥有请求url。 I made .htaccess file under myframework directory like below: 我在myframework目录下制作了.htaccess文件,如下所示:

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

It works for all requests but localhost/myframework/. 它适用于除localhost / myframework /之外的所有请求。 It does nothing when this request is coming. 当此请求到来时,它不执行任何操作。 How can i fix it? 我该如何解决?

This line 这条线

RewriteCond %{REQUEST_FILENAME} !-d

says not to rewrite when the request points to a real directory, which is what localhost/myframework/ is requesting. 表示在请求指向真实目录(即localhost/myframework/所请求的目录)时不重写。 Take it out and your rewrite should kick in. 将其取出,即可开始进行重写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM