由于我是 Laravel 新手,我已经安装了一个新副本,授予必要的权限并运行应用程序,一切都很好。 现在我已经在apache中创建了一个虚拟主机来删除公共(public),这也工作正常:
<VirtualHost *:80>
ServerName mobileapp
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/mobileapp/public
<Directory "/var/www/html/mobileapp/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mobileapp_error.log
CustomLog ${APACHE_LOG_DIR}/mobileapp_access.log combined
现在该站点可以通过 http://mobileapp/index.php/pages 本地访问,但如果我从 url ( http://mobileapp/pages ) 中删除 index.php 则不起作用。 我的 .htaccess 文件是:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L] # <----- Tested not working
RewriteRule ^(.*)$ /$1 [L] # <----- neither this one
我还启用了 mode_rewrite。谁能告诉我骑这辆车最好、最简单的方法是什么。
最佳答案
尝试这个前端 Controller 规则:
RewriteRule ^index\.php(/|$) - [L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/?$ index.php/$1 [L]
关于php - 从 Laravel 5 URL 中删除 public 和 index.php 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32624012/