Laravel htaccess [英] Laravel htaccess

查看:94
本文介绍了Laravel htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地安装了新的Laravel安装.似乎htaccess或Apache设置存在问题.我已经研究了几个小时,并尝试了所有阅读的内容.

I've setup a new install of Laravel on my local. It appears there are issues with htaccess or Apache settings. I've researched for a number of hours and tried everything I read.

  • OSX Lion 10.7.5
  • MAMP 3.0.5
  • PHP 5.5.10
  • 正在加载mod_rewrite.

我的开发服务器可与其他站点一起使用.这是我第一次尝试Laravel 4.

My development server works with other sites. This is the first time I am trying Laravel 4.

我在网站website.dev:8888/

I get a 403 Forbidden on the welcome page which is located at website.dev:8888/

Apache给我这个错误:Options指令禁止使用目录索引

Apache gives me this error: Directory index forbidden by Options directive

这是我的.htaccess文件内容:

Here is my .htaccess file content:

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

以下是我采取的一些其他操作:

Here are a few additional actions I've taken:

  • 在httpd.conf中将"AllowOverride"设置为全部"
  • 在httpd-vhosts.conf中添加了虚拟主机代码部分
  • 验证hosts文件中包含用于网站127.0.0.1 website.dev的行

我还在htaccess中尝试了很多行,我在文章中找到了这些行,并且每次对conf文件进行更改时,我也重新启动了apache.没有路线有效.当我进入website.dev:8888/public时,我得到一个空白页,没有错误.如果我转到创建的路由,例如website.dev:8888/users,则会收到404 not found错误.

I've also tried various lines in the htaccess which I found in articles and I also restarted apache each time I made changes to the conf files. No routes work. When I go to website.dev:8888/public I get a blank page, no error. If I go to a route I created such as website.dev:8888/users I get a 404 not found error.

谢谢您的帮助!

推荐答案

此解决方案效果很好,对我来说是最好的解决方案.将此代码粘贴到根htaccess中.就这样.保留所有其他文件

This solution worked fine, best solution ever for me. Paste this code into root htaccess. That's all. Leave all other files as they are

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

这篇关于Laravel htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆