laravel隐藏index.php的方法:1、开启apache mod_rewrite模块,并修改htaccess文件;2、在nginx配置文件中通过“try_files $uri $uri/...”指令实现隐藏index.php。
laravel 配置 隐藏index.php
Apache
首先保证你的Apache mod_rewrite 模块已经开启. 框架默认有一个 public/.htaccess 文件可以实现隐藏 index.php 的访问.
如果无效的话,可以试试下面的规则:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Nginx
在Nginx配置文件中通过下面的指令实现隐藏 index.php:
location / {
try_files $uri $uri/ /index.php?$query_string;
}