[英]Best way to remove public and index.php from Laravel 5 URLS
As i am new to laravel, i have installed a fresh copy, give necessary permissions and run the application everything is good. 作为laravel的新手,我已经安装了新副本,提供必要的权限并运行该应用程序,一切都很好。 Now i have create a virtual host in apache to remove the public, which is also working fine:
现在我已经在apache中创建了一个虚拟主机以删除公共主机,它也可以正常工作:
<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
Now the site can access locally through http://mobileapp/index.php/pages , but not working if i remove index.php from url ( http://mobileapp/pages ). 现在,该站点可以通过http://mobileapp/index.php/pages在本地访问,但是如果我从url( http:// mobileapp / pages )中删除index.php,该站点将无法正常工作。 My .htaccess file is:
我的.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
I have also enable mode_rewrite. 我还启用了mode_rewrite。 Can any one tell me what is the best and easy way to ride on this.
谁能告诉我什么是最好的,最简单的方法。
Try this front controller rule: 尝试以下前端控制器规则:
RewriteRule ^index\.php(/|$) - [L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/?$ index.php/$1 [L]
To debug rewrites, add the following to your .htaccess
: 要调试重写,请将以下内容添加到
.htaccess
:
RewriteLog ${APACHE_LOG_DIR}/rewrite.log
RewriteLogLevel 9
Then you can try different regular expressions for your RewriteRules to see what happens. 然后,您可以为RewriteRules尝试不同的正则表达式,以查看会发生什么。 I would try something like the following:
我会尝试以下内容:
RewriteRule ^/index.php(.*)$ http://mobileapp/$1 [L]
Remember that for the RewriteRule
to apply, the RewriteCond
lines need to be satisfied first. 请记住,要应用
RewriteRule
,首先需要满足RewriteCond
行。 In your case, you are doing conditions of !-d
and !-f
, so that maybe your issue. 就您而言,您正在执行
!-d
和!-f
,因此可能是您遇到的问题。
我只是将server.php
重命名为index.php
,它可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.