Apache
Laravel 框架自帶了 public/.htaccess
文件用來從網址中刪除
index.php
。如果你用的是 Apache 來運行你的 Laravel 應用,請務必啓用 Apache 的
mod_rewrite
模塊。
如果 Laravel 自帶的 .htaccess
文件在你的 Apache 中不起作用,請試一試下面的配置:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Nginx
在 Nginx 中,將下面的指令放到站點配置文件中就可以實現美化鏈接的功能:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
當然,如果你用的是 Homestead,美化鏈接的功能已經被自動配置好了。