【问题标题】:Apache mod-rewrite rule not workingApache mod-rewrite 规则不起作用
【发布时间】:2016-02-01 08:17:11
【问题描述】:

我正面临 ap​​ache 重写规则的问题。我期待以下结果

If URL is 
          http://www.mysite.co/testWeb/query1/guery2/3
Then Result 
          http://www.mysite.co/testWeb/index.html/#/query1/guery2/3

(index.html/# - 必须在 URL 中添加,路径包含 testWeb)

我添加的规则如下

RewriteEngine On
RewriteRule ^testWeb/(.*)$ http://%{HTTP_HOST}/testWeb/index.html/#/$1 [L]

此规则在重写规则在线测试器中运行良好。但不在我的 apache 中。有什么想法吗?

【问题讨论】:

  • 发生了什么?
  • “不工作”究竟是什么意思?
  • .htaccess 样式文件的解释必须首先在 http 服务器主机配置中启用。原因是这些文件确实会降低服务器速度,因此默认情况下它们是停用的。

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

看起来规则正在您的服务器上创建重定向循环错误,因为您的正则表达式模式也匹配目标 url /testweb/index.html

您需要使用负的 RewriteCond 来防止这种情况。

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/testWeb/index\.html$ [NC]
RewriteRule ^testWeb/(.*)$ http://%{HTTP_HOST}/testWeb/index.html/#/$1 [NC,L,NE]

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 2015-07-26
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2012-03-23
    • 2019-09-13
    • 2011-07-20
    • 2017-07-10
    相关资源
    最近更新 更多