laravel 即使启用了allowoverride .htaccess 也不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7114129/
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
.htaccess not working even though allowoverride is enabled
提问by Dan Matthews
I'm using CodeIgniter and have just installed a LAMP stack on an Ubuntu 10.10 cloud server.
我正在使用 CodeIgniter 并且刚刚在 Ubuntu 10.10 云服务器上安装了 LAMP 堆栈。
Everything is working great, and I have the Apache userdir module enabled so that my home directory sits at /home/myapp/public_html, and I access it by going to servername/~myapp.
一切正常,我启用了 Apache userdir 模块,以便我的主目录位于/home/myapp/public_html,我可以通过转到servername/~myapp.
Unfortuntely, .htaccessrewrite does not seem to be working - it causes a 404 saying the file /home/myapp/public_html/index.phpcould not be found - a 404 error.
不幸的是,.htaccess重写似乎不起作用 - 它导致 404 说the file /home/myapp/public_html/index.php无法找到 - 404 错误。
Mod_rewrite is enabled.
Mod_rewrite 已启用。
I'm aware that you need to set the AllowOverride Alldirective - I have it set in /etc/apache2/sites-enabled/default- yet rewrite doesn't seem to be working properly.
我知道您需要设置AllowOverride All指令 - 我已经设置了/etc/apache2/sites-enabled/default- 但重写似乎无法正常工作。
My .htaccessfile simply contains:
我的.htaccess文件只包含:
RewriteEngine on
RewriteCond !^(index.php|img|stylesheets|js|icons|robots\.txt|user_guide)
RewriteRule ^(.*)$ index.php/ [L]
And my /etc/apache2/sites-available/defaultlooks like:
我的/etc/apache2/sites-available/default样子:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
And finally, /etc/apache2/mods-enabled/userdir.conflooks like:
最后,/etc/apache2/mods-enabled/userdir.conf看起来像:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
I've been googling and fiddling for hours, can anyone help please?
我一直在谷歌搜索和摆弄几个小时,有人可以帮忙吗?
回答by jonas
For what it's worth, I had a very similar problem with Ubuntu Server 11.10 and LAMP. I had to run the command
对于它的价值,我在 Ubuntu Server 11.10 和 LAMP 上遇到了非常相似的问题。我必须运行命令
sudo a2enmod rewrite
which did the trick for me. Maybe it's the solution for you or some other people coming in here.
这对我有用。也许这是您或其他一些人来到这里的解决方案。

