在lamp环境下利用还是蛮大略,配置Laravel/public/.htaccess:
Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]
即可,访问的地址:
http://test.comlaravel1/public/admin/index

http://test.com/laravel2/public/admin/index
nginx做事器
文档中说,只要在nginx.conf下配置:
location / { try_files $uri $uri/ /index.php?$query_string;}
即可,访问优雅链接,但结果有点失落望,你会碰着问题:
Access denied.No input file specified.504...归根结底是nginx.conf配置问题,本人碰着最多便是Access denied,由于利用OneinStack自动支配lnmp环境,nginx.conf已经默认配置了,结果仔细比拟,少了下面配置
fastcgi_split_path_info ^(.+\.php)(.)$;
参考:https://segmentfault.com/a/1190000002667095
难怪laravel优雅链接index.php后面一贯无法访问,目前为题已办理,附上一段网上的配置:
server { listen 80; server_name _; set $root_path '/data/www/default'; root $root_path; index index.php index.html index.htm; try_files $uri $uri/ @rewrite; location @rewrite { rewrite ^/(.)$ /index.php?_url=/$1; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index /index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;} location ~ ^/(css|img|js|flv|swf|download)/(.+)$ { root $root_path; } location ~ /\.ht { deny all; } }
http://test.com/laravel1/public/index.php/admin/index
http://test.com/laravel2/public/index.php/admin/index
都可以正常访问了,OK!
末了隐蔽index.php
虽然上述配置在laravel中可以正常访问,但是一些放在public里面的静态资源可能无法访问,比如无法利用asset()函数时,路径中就包含index.php导致资源无法加载,以是建议隐蔽index.php
if (!-e $request_filename) { rewrite ^/(.)/public/(.)$ /$1/public/index.php/$2 last; break;}
http://test.com/laravel1/public/admin/index
http://test.com/laravel2/public/admin/index
以上就无需加index.php,即可正常访问