【问题标题】:.htaccess not working even though allowoverride is enabled即使启用了allowoverride,.htaccess 也不起作用
【发布时间】:2011-10-30 03:47:46
【问题描述】:

我正在使用 CodeIgniter,并且刚刚在 Ubuntu 10.10 云服务器上安装了 LAMP 堆栈。

一切正常,我启用了 Apache userdir 模块,因此我的主目录位于 /home/myapp/public_html,我通过转到 servername/~myapp 来访问它。

不幸的是,.htaccess rewrite 似乎不起作用 - 它会导致 404 提示无法找到 the file /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 dan@danmatthews.me

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>

我已经在谷歌上搜索和摆弄了几个小时,有人可以帮忙吗?

【问题讨论】:

    标签: apache codeigniter ubuntu laravel


    【解决方案1】:

    不管怎样,我在 Ubuntu Server 11.10 和 LAMP 上遇到了非常相似的问题。我必须运行命令

    sudo a2enmod rewrite
    

    这对我有用。也许这是您或其他人来这里的解决方案。

    【讨论】:

    • 这也对我有用....在 Ubuntu 10.10 中使用 laravel 时遇到同样的问题...
    • 在 ubu 12.04LTS 上我也遇到了这个问题,它成功了!!,很高兴我们有类似 stackoverflow 的东西!
    猜你喜欢
    • 2020-04-17
    • 2023-03-14
    • 2017-12-11
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多