【问题标题】:Apache rewrite rule for whole directory整个目录的 Apache 重写规则
【发布时间】:2012-05-26 10:32:17
【问题描述】:

我想设置一个重写规则

RewriteRule /test /my/long/path/index.html

但是我的 index.html 通过 ajax 获取其他文件,所以它不像这样简单。我需要为目录的所有子文件制定规则
我试过了:

RewriteRule /test /my/long/path/
RewriteRule /test/* /my/long/path/*

但我最终得到了一个有趣的重定向http://my.domain.co/test/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/

对不起,我对 Apache 的无知,谢谢

【问题讨论】:

  • 我认为你需要在 /test 之后有一个/。否则,对于 <img src="plaatje.jpg" /> 之类的引用,浏览器会在根 (/) 中查找 plaatje.jpg,而不是在 /test 文件夹中。
  • RewriteRule /test/ /my/long/path/index.html,同样的,页面无法完全加载,因为 /my/long/path/index.html 获取一些文件,如 /my/ long/path/file.json,在/test/file.json中找不到它们

标签: apache mod-rewrite


【解决方案1】:

您的 RewriteRule 无效。试试这个:

RewriteRule ^test(/.*)?$ my/long/path$1

【讨论】:

  • 我试过了,但浏览器显示my.domain.co/test/index.htmlmy.domain.co/test 找不到
  • 你设置RewriteEngine On并把.htaccess放到根目录了吗?
  • 是的,RewriteEngine On,没有放.htaccess,url重写需要吗?
  • 你的 RewriteRule 存储在哪里?
  • in /etc/apache2/sites-available/default (ubuntu) RewriteEngine On RewriteRule ...
猜你喜欢
  • 2014-04-25
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
相关资源
最近更新 更多