【问题标题】:How to run htaccess rewrite code on localhost如何在本地主机上运行 htaccess 重写代码
【发布时间】:2014-07-25 11:00:28
【问题描述】:
   SecFilterEngine Off
    DirectorySlash Off
    Options -Indexes

    ErrorDocument 404 /not-found.php
    ErrorDocument 403 /not-found.php

    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} ^xyz.com.au$ [NC]
    RewriteRule ^(.*)$ http://someurl.au/$1 [R=301,L]

    # RewriteCond %{QUERY_STRING} ^.+$
    # RewriteRule ^$ ? [R=301,L]

    RewriteRule ^news_and_events.asp news-and-views? [NC,R=301,L]
    RewriteRule ^detailapplication.asp products/applications? [NC,R=301,L]
    RewriteRule ^detailproduct.asp products/products? [NC,R=301,L]
    RewriteRule ^detailproduct.asp products/products? [NC,R=301,L]
    RewriteRule ^products.asp products/products? [NC,R=301,L]

此代码在服务器上正常工作,但在本地主机上不工作。请有人告诉我必要的更改。在那个 url 中,我认为需要将该 url 更改为 localhost,我在那里添加了 localhost 但仍然无法正常工作,请告诉我问题

【问题讨论】:

  • 也许你没有加载所有的 apache 模组来使用SecFilterEngine 甚至ModRewrite?如果你告诉我们什么是行不通的,这很好,例如。你得到一个Internal Server Error 或者只是RewriteRules 不工作......
  • 服务器错误!错误号 500
  • 看看我的第一条评论
  • 我收到服务器错误500,请告诉我如何解决

标签: php localhost


【解决方案1】:

如果您的项目使用不同的文件夹,请在 RewriteBase 中添加您的文件夹名称,如下所示。

RewriteBase /YOUR_PROJECT_FOLDER/

还删除以下行。本地主机不需要。

RewriteCond %{HTTP_HOST} ^xyz.com.au$ [NC]
RewriteRule ^(.*)$ http://someurl.au/$1 [R=301,L]

【讨论】:

  • 需要在localhost上配置
【解决方案2】:

我建议打开重写日志,以便您查看实际发生的情况。

我不知道您使用的是什么版本的 apache,甚至不知道操作系统,因此请尝试将其添加到您的 httpd.conf 或该站点的虚拟主机定义中,但不在 .htaccess 文件中

对于 Apache 2.2 rewrite log Doc 像这样

RewriteEngine On
RewriteLog "full/path/to/rewrite.log"
RewriteLogLevel 3

如果您使用的是 Apache 2.4 rewrite log Doc,则语法已更改为类似这样

RewriteEngin On
RewriteLog "full/path/to/rewrite.log"
LogLevel alert rewrite:trace6

【讨论】:

    【解决方案3】:

    首先尝试删除SecFilterEngine Off,因为它需要默认未安装的mod_security。

    如果仍然无法正常工作,请检查您的 httpd.conf。 mod_rewrite 需要被激活。 See this answer.

    如果它仍然不起作用,可能AllowOverride 设置为无。

    【讨论】:

      猜你喜欢
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 2012-01-29
      • 1970-01-01
      • 2018-07-20
      • 2019-10-21
      相关资源
      最近更新 更多