【问题标题】:mod_rewrite is not working in vagrantmod_rewrite 在 vagrant 中不起作用
【发布时间】:2016-04-03 12:54:35
【问题描述】:

我是流浪世界的新手 :-)

使用 Ubuntu 15.10, VirtualBox 5.0, Vagrant 1.8.1 并安装了 precise32 盒子

在我的盒子里,我根据需要安装了 Apache2、php5 和 mysql

加载的模块:

core mod_log_config mod_logio prefork http_core mod_so mod_alias mod_auth_basic mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_deflate mod_dir mod_env mod_mime mod_negotiation mod_php5 mod_reqtimeout mod_rewrite mod_setenvif mod_ssl mod_status

启用 SSL

Vagrant VirtualHost ssl 文件

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin admin@example.com
        ServerName mysite.com
        ServerAlias www.mysite.com
        DocumentRoot /vagrant/www

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        </FilesMatch>

        <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
        </Directory>

        BrowserMatch "MSIE [2-6]" \
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>

我尝试将以下代码添加到我的 SSL 虚拟主机中,但仍然没有成功:-(

<Directory "/vagrant/www">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order deny,allow
   allow from all
</Directory>

Vagrantfile 配置:

Vagrant.configure(2) do |config|
    config.vm.box = "precise32"
  config.vm.network "private_network", ip: "10.0.0.7"
  config.vm.synced_folder "~/myvm/www", "/vagrant_data"
end

我的主页(index.php)工作正常,但内页打不开,请建议如何在 vagrant 中正确配置/启用 .htaccess 和 mod_rewrite ?

【问题讨论】:

    标签: apache mod-rewrite vagrant vagrantfile ubuntu-15.10


    【解决方案1】:

    对于.htaccess,需要在目录标签下添加AllowOverride指令:

    <Directory "/var/www">
        AllowOverride All
    </Directory>
    

    应该可以的。

    编辑

    这可能有帮助,也可能没有帮助,但在 15.10 中,我相信 apache 的 PPA 版本是 2.4,它使用 Require 指令:

    <Directory "/vagrant/www">
       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order deny,allow
       allow from all
       Require all granted
    </Directory>
    

    注意添加Require all granted。

    【讨论】:

    • 我已经尝试过但不走运,请查看我修改后的问题并指导我如何解决这个问题?谢谢
    • @zarpio 更新了我的答案。如果这不起作用,我就没主意了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2013-04-26
    • 2018-05-16
    • 2011-06-29
    • 2013-07-18
    • 1970-01-01
    • 2017-08-07
    相关资源
    最近更新 更多