Mod rewrite 重写/“foo/bar”;至;index.html“;加上“;"富",;指向所有相关URL

Mod rewrite 重写/“foo/bar”;至;index.html“;加上“;"富",;指向所有相关URL,mod-rewrite,Mod Rewrite,我正在尝试将所有传入的URL(不链接到文件系统上的物理文件)重写到我的index.html(并进一步使用history.js处理URL) 我的访问权限: localhost/www.xy.de/工作正常,但是 localhost/www.xy.de/不太可能。即使在第二个示例中,它也被重定向到index.html,但发生了一些奇怪的事情: 重写.log: (如下所示,以便更好地阅读) 问题在于这一行: 添加路径信息后缀:/srv/http/www.xy.de/yxc->/srv/http/www

我正在尝试将所有传入的URL(不链接到文件系统上的物理文件)重写到我的index.html(并进一步使用history.js处理URL)

我的访问权限:
localhost/www.xy.de/
工作正常,但是

localhost/www.xy.de/
不太可能。即使在第二个示例中,它也被重定向到index.html,但发生了一些奇怪的事情:

重写.log: (如下所示,以便更好地阅读)

问题在于这一行:

添加路径信息后缀:/srv/http/www.xy.de/yxc->/srv/http/www.xy.de/yxc/static/main.css
html文件中的所有图像/脚本/样式表(以及所有相关链接)都会发生这种情况,当然,由于没有带有此前缀的文件,因此所有内容都会重定向到index.html,所有内容都会出错

为什么Web服务器将
yxc
添加到路径中?如何防止这种行为?

为什么Web服务器将yxc添加到路径中?我怎样才能防止这种行为

这就是相对链接的工作原理。浏览器尝试确定使用请求的URI的URI库。因此,当浏览器请求
http://localhost/ww.xy.de/yxc/z
,URI是
/www.xy.de/yxc/z
,基础是
/www.xy.de/yxc/
。有了这个基础,所有相关链接都将在链接的前面附加这个

您需要将所有链接更改为绝对链接,或者添加

<base href="/www.xy.de/">

指向index.html页面的标题

[...][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]
<base href="/www.xy.de/">