【问题标题】:.htaccess not working on live system.htaccess 在实时系统上不起作用
【发布时间】:2017-01-05 21:37:03
【问题描述】:

我正在使用以下 .htaccess 规则:

RewriteRule ^news/(.*),(.*).html$   news.php?id=$2 [L]

当使用例如。以下网址:

http://www.foo.com/news/bar,303.html

它适用于我的本地 xampp,但不适用于实时服务器.. var_dump($_GET) 返回一个空数组,因此过滤器没有定义 id 参数。 有什么想法有什么问题吗?

编辑:我安装了 mod_rewrite,它适用于大多数链接,但不是这个..

【问题讨论】:

  • 确保你的实时服务器上安装并运行了 mod rewrite
  • 如果var_dump($_GET) 完全是空的,那么就大错特错了。即使脚本确实使用...?id= 执行并且没有值,您仍然会在数组中有$_GET['id'] = null
  • 是的,这正是问题所在:D

标签: php .htaccess xampp


【解决方案1】:

您的规则似乎没问题。在您的实时服务器上,MultiViews 选项可能已启用。要关闭它,请使用:

Options -MultiViews

在您的 .htaccess 顶部。

选项MultiViews(参见http://httpd.apache.org/docs/2.4/content-negotiation.html)由运行之前 mod_rewriteApache's content negotiation module 使用,并使Apache 服务器匹配文件的扩展名。因此,如果 /news 是 URL,那么 Apache 将提供 /news.php

【讨论】:

    【解决方案2】:

    假设你安装了 mod_rewrite,它可能没有全局激活,需要激活

     RewriteEngine On
     RewriteBase /news/
     RewriteRule ^news/(.*),(.*).html$   news.php?id=$2 [L]
    

    例如;打开重写,并指定直接将规则应用到哪个

    【讨论】:

      【解决方案3】:

      您可能希望从 apache 启用重写模块

      打开终端并执行以下代码

      sudo a2enmod rewrite
      sudo service apache2 restart
      

      现在要使用重写模块,请按照以下步骤操作。

      1. 使用以下命令在任意编辑器中打开默认的 Apache 配置文件。
      sudo nano /etc/apache2/sites-enabled/000-default.conf
      
      1. 在该文件中,您会在第 1 行找到该块。在该块中,添加以下块:
      <Directory /var/www/html>
                      Options Indexes FollowSymLinks MultiViews
                      AllowOverride All
                      Order allow,deny
                      allow from all
      </Directory>
      

      再次重启apache

      sudo service apache2 restart
      

      了解更多关于重写模块Click here

      • 注意:确保您有专门的服务器来执行上述步骤。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-24
        • 1970-01-01
        • 2014-02-04
        • 2016-04-18
        • 2016-01-11
        • 2012-12-31
        • 2013-03-22
        • 1970-01-01
        相关资源
        最近更新 更多