我正在尝试将所有传入的 url(不链接到文件系统上的物理文件)重写为我的 index.html(并进一步处理带有 history.js 的 url)
我的 htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# Rewrite everything that isn't a real file to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ www.xy.de/index.html
localhost/www.xy.de/<foo>
完美运行,但是
localhost/www.xy.de/<foo>/<bar>
并不真地。即使在第二个示例中,它也被重定向到 index.html,但发生了一些奇怪的事情:
重写日志:
http://sprunge.us/GiEM(下同以便更好地阅读)
[...][rid#1dfc7e0/initial] (3) [perdir /srv/http/www.xy.de/] add path info postfix: /srv/http/www.xy.de/yxc -> /srv/http/www.xy.de/yxc/z
[...][rid#1dfc7e0/initial] (3) [perdir /srv/http/www.xy.de/] strip per-dir prefix: /srv/http/www.xy.de/yxc/z -> yxc/z
[...][rid#1dfc7e0/initial] (3) [perdir /srv/http/www.xy.de/] applying pattern '^(.+)$' to uri 'yxc/z'
[...][rid#1dfc7e0/initial] (4) [perdir /srv/http/www.xy.de/] RewriteCond: input='/srv/http/www.xy.de/yxc' pattern='!-f' => matched
[...][rid#1dfc7e0/initial] (4) [perdir /srv/http/www.xy.de/] RewriteCond: input='/srv/http/www.xy.de/yxc' pattern='!-d' => matched
[...][rid#1dfc7e0/initial] (2) [perdir /srv/http/www.xy.de/] rewrite 'yxc/z' -> 'www.xy.de/index.html'
[...][rid#1dfc7e0/initial] (3) [perdir /srv/http/www.xy.de/] add per-dir prefix: www.xy.de/index.html -> /srv/http/www.xy.de/www.xy.de/index.html
[...][rid#1dfc7e0/initial] (2) [perdir /srv/http/www.xy.de/] trying to replace prefix /srv/http/www.xy.de/ with /
[...][rid#1dfc7e0/initial] (5) strip matching prefix: /srv/http/www.xy.de/www.xy.de/index.html -> www.xy.de/index.html
[...][rid#1dfc7e0/initial] (4) add subst prefix: www.xy.de/index.html -> /www.xy.de/index.html
[...][rid#1dfc7e0/initial] (1) [perdir /srv/http/www.xy.de/] internal redirect with /www.xy.de/index.html [INTERNAL REDIRECT]
[...][rid#1e08850/initial/redir#1] (3) [perdir /srv/http/www.xy.de/] strip per-dir prefix: /srv/http/www.xy.de/index.html -> index.html
[...][rid#1e08850/initial/redir#1] (3) [perdir /srv/http/www.xy.de/] applying pattern '^(.+)$' to uri 'index.html'
[...][rid#1e08850/initial/redir#1] (4) [perdir /srv/http/www.xy.de/] RewriteCond: input='/srv/http/www.xy.de/index.html' pattern='!-f' => not-matched
[...][rid#1e08850/initial/redir#1] (1) [perdir /srv/http/www.xy.de/] pass through /srv/http/www.xy.de/index.html
[...][rid#1e00800/initial] (3) [perdir /srv/http/www.xy.de/] add path info postfix: /srv/http/www.xy.de/yxc -> /srv/http/www.xy.de/yxc/static/main.css
[...][rid#1e00800/initial] (3) [perdir /srv/http/www.xy.de/] strip per-dir prefix: /srv/http/www.xy.de/yxc/static/main.css -> yxc/static/main.css
[...][rid#1e00800/initial] (3) [perdir /srv/http/www.xy.de/] applying pattern '^(.+)$' to uri 'yxc/static/main.css'
[...][rid#1e00800/initial] (4) [perdir /srv/http/www.xy.de/] RewriteCond: input='/srv/http/www.xy.de/yxc' pattern='!-f' => matched
[...][rid#1e00800/initial] (4) [perdir /srv/http/www.xy.de/] RewriteCond: input='/srv/http/www.xy.de/yxc' pattern='!-d' => matched
[...][rid#1e00800/initial] (2) [perdir /srv/http/www.xy.de/] rewrite 'yxc/static/main.css' -> 'www.xy.de/index.html'
[...][rid#1e00800/initial] (3) [perdir /srv/http/www.xy.de/] add per-dir prefix: www.xy.de/index.html -> /srv/http/www.xy.de/www.xy.de/index.html
[...][rid#1e00800/initial] (2) [perdir /srv/http/www.xy.de/] trying to replace prefix /srv/http/www.xy.de/ with /
[...][rid#1e00800/initial] (5) strip matching prefix: /srv/http/www.xy.de/www.xy.de/index.html -> www.xy.de/index.html
[...][rid#1e00800/initial] (4) add subst prefix: www.xy.de/index.html -> /www.xy.de/index.html
[...][rid#1e00800/initial] (1) [perdir /srv/http/www.xy.de/] internal redirect with /www.xy.de/index.html [INTERNAL REDIRECT]
问题出在这一行:
add path info postfix: /srv/http/www.xy.de/yxc -> /srv/http/www.xy.de/yxc/static/main.css
这发生在 html 文件中的所有图像/脚本/样式表(因此所有相关链接)上,当然,由于没有具有此前缀的文件,所有内容都被重定向到 index.html 并且一切都搞砸了。
为什么网络服务器会添加yxc
到路径中?我怎样才能防止这种行为?