Laravel 默认的 .htaccess 文件将不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17228936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel default .htaccess file will not work
提问by MasterZ
I finally got everything installed for Laravel, but I am getting an error 500 on my home page!
我终于为 Laravel 安装了所有东西,但我的主页上出现错误 500!
It looks to be my .htaccess file. If I remove it the page works. If I put it back, another error 500.
它看起来是我的 .htaccess 文件。如果我删除它,页面就可以工作。如果我把它放回去,另一个错误 500。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If I change that second to last line to "RewriteRule ^index.php [L]" (no space before index.php) then the error 500 goes away but the rewrite rule will not work.
如果我将倒数第二行更改为“RewriteRule ^index.php [L]”(index.php 之前没有空格),那么错误 500 就会消失,但重写规则将不起作用。
My host is 1and1.com.
我的主机是 1and1.com。
Can anybody help me?
有谁能够帮助我?
回答by MasterZ
Changed this line:
改变了这一行:
RewriteRule ^ index.php [L]
to this:
对此:
RewriteRule ^ /index.php [L]
Now it works. Not only do I not get the 500 error, but the URLs appear to work as intended.
现在它起作用了。我不仅没有收到 500 错误,而且 URL 似乎按预期工作。
回答by saran banerjee
It seems to me the 500 internal error is coming because you have not set the virtual host in the apache httpd.conf file.
在我看来,500 内部错误即将到来,因为您尚未在 apache httpd.conf 文件中设置虚拟主机。
Put this line in the httpd.conf file
将此行放在 httpd.conf 文件中
For windows
窗户用
NameVirtualHost *:80
<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "C:/wamp/www/laravel/public"
<Directory "C:/wamp/www/laravel/public">
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
</Directory>
</VirtualHost>
For Linux
对于 Linux
NameVirtualHost *:80
<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "/var/www/laravel/public"
<Directory "/var/www/laravel/public">
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/var/www"
<Directory "/var/www">
</Directory>
</VirtualHost>
And to run it in your local machine
并在您的本地机器上运行它
For window open the C:\Windows\System32\drivers\etc\hosts put this line.
对于窗口打开 C:\Windows\System32\drivers\etc\hosts 放这一行。
yourserverip yourlaravel.com
For linux open the \etc\hosts put this line.
对于 linux 打开 \etc\hosts 放这一行。
yourserverip yourlaravel.com
Your can refer to this link for further info:
您可以参考此链接了解更多信息:
http://net.tutsplus.com/tutorials/php/building-web-applications-from-scratch-with-laravel/
http://net.tutsplus.com/tutorials/php/building-web-applications-from-scratch-with-laravel/
I hope this can be some help.
我希望这可以有所帮助。
回答by Vinod Raut
It work for me on the most of the project where default one won't work
它在大多数项目中对我有用,默认一个不起作用
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}:: ^(/.+)/(.*)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
回答by PJJ
I had a similar issue, and the error suddenly happened overnight.
我有一个类似的问题,错误突然发生在一夜之间。
I have searched all over google and Stackoverflow, but i couldn't find any solutions to fix this problem, and i kept getting a 500 Internal Server error.
我已经在 google 和 Stackoverflow 上进行了搜索,但找不到任何解决方案来解决这个问题,而且我一直收到 500 Internal Server 错误。
I was on a shared hosting, and even renaming the .htaccess file didn't work.
我在共享主机上,甚至重命名 .htaccess 文件也没有用。
At the buttom of .htaccess i put
在 .htaccess 的底部我放了
php_flag opcache.enable 0
right before the ending </IfModule>
. This solved the problem for me.
就在结局之前</IfModule>
。这为我解决了这个问题。
回答by Sambada Budiarga
I also experienced this issue and solved it by commenting option line in .htaccess file..
我也遇到过这个问题,并通过在 .htaccess 文件中注释选项行来解决它。
Using apache 2.4.x
使用 apache 2.4.x
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
It may conflicting with the site configuration. Because it cannot have multiple condition with different operator.
它可能与站点配置冲突。因为它不能具有不同运算符的多个条件。
I cannot find the link yet. But I've read it somewhere before.
我还找不到链接。但我以前在某处读过它。
EDIT: Found the link.
编辑:找到链接。
Note
Mixing Options with a + or - with those without is not valid syntax and will be rejected during server startup by the syntax check with an abort.
笔记
将带有 + 或 - 的选项与那些没有的混合是无效的语法,并且会在服务器启动期间通过带有中止的语法检查而被拒绝。
Just make sure your .htaccess and apache configuration is not conflicting each other.
只要确保您的 .htaccess 和 apache 配置不会相互冲突。