当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>
答案 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]