即使启用了allowoverride,.htaccess 也不起作用
我正在使用 CodeIgniter,并且刚刚在 Ubuntu 10.10 云服务器上安装了 LAMP 堆栈。
一切都运行良好,我启用了 Apache userdir 模块,以便我的主目录位于 /home/myapp/public_html,我可以通过转到 servername/~myapp
来访问它代码>.
不幸的是,.htaccess
重写似乎不起作用 - 它会导致 404 提示 找不到文件 /home/myapp/public_html/index.php
- 404错误。
Mod_rewrite 已启用。
我知道您需要设置 AllowOverride All
指令 - 我已在 /etc/apache2/sites-enabled/default
中设置它 - 但重写似乎并不存在才能正常工作。
我的 .htaccess
文件只包含:
RewriteEngine on
RewriteCond $1 !^(index.php|img|stylesheets|js|icons|robots\.txt|user_guide)
RewriteRule ^(.*)$ index.php/$1 [L]
我的 /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
最后,/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'm using CodeIgniter and have just installed a LAMP stack on an Ubuntu 10.10 cloud server.
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
.
Unfortuntely, .htaccess
rewrite does not seem to be working - it causes a 404 saying the file /home/myapp/public_html/index.php
could not be found - a 404 error.
Mod_rewrite is enabled.
I'm aware that you need to set the AllowOverride All
directive - I have it set in /etc/apache2/sites-enabled/default
- yet rewrite doesn't seem to be working properly.
My .htaccess
file simply contains:
RewriteEngine on
RewriteCond $1 !^(index.php|img|stylesheets|js|icons|robots\.txt|user_guide)
RewriteRule ^(.*)$ index.php/$1 [L]
And my /etc/apache2/sites-available/default
looks like:
<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.conf
looks like:
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,我在 Ubuntu Server 11.10 和 LAMP 上遇到了非常相似的问题。我必须运行
对我有用的命令。也许这就是您或其他来到这里的人的解决方案。
For what it's worth, I had a very similar problem with Ubuntu Server 11.10 and LAMP. I had to run the command
which did the trick for me. Maybe it's the solution for you or some other people coming in here.