这是我的完整案例:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?$1 [QSA,L]
</IfModule>
<VirtualHost 127.0.0.3:80>
ServerName mvcframe.local
DocumentRoot /var/www/html/mvcframework/public
<Directory /var/www/html/mvcframework>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog /var/www/html/mvcframework/mvc-error.log
CustomLog /var/www/html/mvcframework/mvc-access.log combined
</VirtualHost>
当我访问http://mvcframe.local或http://mvcframe.local/时,它会按需要在公用文件夹index.php中输出index.php内容。
Requested URL = posts/hello
Not Found
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at mvcframe.local Port 80
我试图找出解决方案2个小时,但仍然没有找到解决方案。
好吧,所以在弄乱并阅读了数小时的.htaccess教程后,我终于设法理解了我的错误。首先,这是帮助我了解我的错误的视频。
这是我的解决方案:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?$1 [QSA,L]
</IfModule>
首先,我要检查是否启用了mod_rewrite。然后提供一些选择。然后打开RewriteEngine,这对于启用重写规则是必需的。然后为要提供的任何查询提供[如果没有目录]和[如果不是文件]的重写条件,我将为其重写规则,基本上是告诉它检查所有以扩展名“。”结尾的字符串。将它们全部定向到index.php?$ 1。
基本上任何具有mvcframe.local / something_here / some_here / ...的东西都会自动变为mvcframe.local / index.php?something_here / some_here
对于我的设置,index.php是前端加载程序,因此所有内容都必须通过此文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句