Ale*_*xnl 6 .htaccess laravel-4 laravel-routing
我已经在本地安装了 Laravel 的新安装。htaccess 或 Apache 设置似乎存在问题。我已经研究了几个小时并尝试了我阅读的所有内容。
我的开发服务器与其他站点一起工作。这是我第一次尝试 Laravel 4。
我在位于 website.dev:8888/ 的欢迎页面上收到 403 Forbidden
Apache 给了我这个错误:选项指令禁止目录索引
这是我的 .htaccess 文件内容:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
以下是我采取的一些额外措施:
我还在文章中找到的 htaccess 中尝试了各种行,并且每次更改 conf 文件时我也重新启动了 apache。没有路线工作。当我访问 website.dev:8888/public 时,我得到一个空白页面,没有错误。如果我转到我创建的路线,例如 website.dev:8888/users,我会收到 404 not found 错误。
感谢您的帮助!
Moh*_* H. 17
这个解决方案效果很好,对我来说是最好的解决方案。将此代码粘贴到 root htaccess 中。就这样。保留所有其他文件不变
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
Run Code Online (Sandbox Code Playgroud)
这是我发现有效的方法。删除目录.htaccess中的文件/public,然后将以下内容放入 laravel 安装的文档根目录中。
因此,为了澄清您的 Laravel 应用程序是否安装在/public_html/laravel您的位置,您将查看内部/public_html/laravel/public并删除.htaccess那里的文件。然后在/public_html/laravel目录中创建一个新文件,名为.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /public/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
正如Concordus 应用程序在其答案中指出的那样,请确保未注释(确保您的 apache 配置文件中其后面Loadmodule mod_rewrite没有符号)#
Concordus 应用程序还指出,您应该AllowOverride设置为适当的设置。他们给出的例子如下。
<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
如果您对 apache 配置文件进行了任何更改,请确保重新启动您的 apache 服务器。
该框架附带一个public/.htaccess文件,用于允许不带index.php. 如果您使用 Apache 为 Laravel 应用程序提供服务,请务必启用该mod_rewrite模块。
如果.htaccessLaravel 附带的文件不适用于您的 Apache 安装,请尝试以下文件:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Run Code Online (Sandbox Code Playgroud)
小智 5
在根路径中创建一个 .htaccess 文件
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
在公共目录中创建一个 .htaccess 文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
如果您在 public/index.php 文件中进行了任何更改,并使用正确的路径更正它们,那么您的站点就会上线。
这将解决什么问题?
接受的答案有效,但不适用于 laravel 护照身份验证。
需要添加一些标头调整:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
Run Code Online (Sandbox Code Playgroud)
小智 5
此 .htaccess 将从您的 URL 中删除 /public/ 并强制使用 https://
将此 .htaccess 放在根文件夹中,无需将 server.php 文件重命名为 index.php,此 .htaccess 将执行所有操作
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)