Laravel 5.2路由仅适用于根目录

时间:2016-04-28 22:00:32

标签: php apache laravel xampp laravel-5.2

当Laravel安装在非根域的文件夹中时,我无法访问我的路由(404)。

例如,如果我在根域中安装Laravel并添加路由anyroutes,我可以毫无问题地访问localhost/anyroutes

BUT

如果我在像localhost/project/这样的文件夹中安装Laravel并添加该路由:localhost/project/public/anyroutes它会给我404.我必须提到localhost/project/public/index.php/anyroutes会工作。

我在早期版本的Laravel中没有遇到这个问题。

我该如何解决这个问题?

Apache(XAMPP),PHP 7,mod_rewrite已启用且

更新

.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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

apache conf:

<Directory />
    Allowoverride All
   # AllowOverride none
    Require all denied
</Directory>


DocumentRoot "E:/projects"
<Directory "E:/projects">

    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride All

    Require all granted
</Directory>

1 个答案:

答案 0 :(得分:0)

这是我的.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]