这是我在 laravel 中默认的.htaccess
,它可以帮助我防止打字public/index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
所以,如果我需要访问
localhost/public/index.php/home
localhost/public/index.php/login
对我来说打字就足够
了localhost/home
localhost/login
我想为少数目录例外,例如"testproject"和"betaproject",即我将有一个常规的 php 或 html 目录,或者我将有另一个新项目并且它也将具有相同的 .htaccess。
我怎样才能修改我的 .htaccess 文件以使其成为可能。
这样如果我想访问
localhost/testproject/public/index.php/home
应可通过localhost/testproject/home
访问
在你的根 .htaccess 中,有这个规则来跳过 2 个目录:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(testproject|betaproject)/('w+)/?$ $1/public/index.php/$2 [L,NC]
确保此规则位于RewriteEngine On
行下方的第一个。