Url rewriting .htcaccess重写规则在本地主机上不起作用
我正在从事一个mvc php项目,但在.htcaccess文件方面遇到了问题。 我想通过index.php路由所有内容。但当我键入时,它不会重定向到index.php,它会显示一个错误404,当我键入时,它会工作。顺便说一句,我对mvc和路由非常陌生Url rewriting .htcaccess重写规则在本地主机上不起作用,url-rewriting,localhost,apache2,Url Rewriting,Localhost,Apache2,我正在从事一个mvc php项目,但在.htcaccess文件方面遇到了问题。 我想通过index.php路由所有内容。但当我键入时,它不会重定向到index.php,它会显示一个错误404,当我键入时,它会工作。顺便说一句,我对mvc和路由非常陌生 .htcaccess code: <IfModule mod_rewrite.so> Options -Multiviews RewriteEngine On RewriteBase /mvc
.htcaccess code:
<IfModule mod_rewrite.so>
Options -Multiviews
RewriteEngine On
RewriteBase /mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?url=$1 [QSA,L]
</IfModule>
.htcaccess代码:
选项-多视图
重新启动发动机
重写BASE/mvc/public
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(+)$/index.php?url=$1[QSA,L]
在最后一行试试这个:
RewriteRule ^(.+)$ /mvc/public/index.php?url=$1 [QSA,L]
你的目标应该是做
/mvc/public/test
而不是/mvc/public/test.php
,在你的路由器中预先添加.php
from?url=
值。尽管听起来像是在做一个包含($\u GET['url'])
,这是一个糟糕的MVC设计,但您不应该基于路由加载文件,而是调用控制器方法,在任何时候都不应该使用该值来加载文件。