此问题涉及另一个主题:Creating Ajax website with links of multiple subfolders is failing . 另请查看找到该问题解决方案的讨论。
我目前对该解决方案的问题是,当现在位于 example.net/about 之类的子网站上时,我的 SVG 元素使用的所有 ID 都找不到了。所以我所有的文本路径都位于我 map 上的 0,0 坐标上,而不是我给它们的特定路径。此外,SVG 图形不再位于正确的位置。但是在 example.net 上一切仍然正常!
让我们以下面的例子为例,它只是我的 500 个元素之一,而且只是 textpath 元素。这在 abc.net 上按预期工作,但在 abc.net/about 上找不到 ID:
<path id="text1" d="M1585.621635966945,...some long path..."></path>
<textPath xlink:href="#text1">Some Text</textPath>
这肯定有意义,因为在 example.net/about#text1 上没有这样的 ID。所以我在考虑更改 href url。在下文中,我向您展示了我的尝试以及它是否适用于“页面(example.net)”或“子页面(example.net/about)”:
-
<textPath xlink:href="#text1">Some Text</textPath>
页面工作,子页面不工作 -
<textPath xlink:href="http://example.net/#text1">Some Text</textPath>
页面工作,子页面不工作 -
<textPath xlink:href="http://example.net/text1">Some Text</textPath>
页面不工作,子页面不工作 -
<textPath xlink:href="http://example.net/index.html#text1">Some Text</textPath>
页面不工作,子页面不工作 -
<textPath xlink:href="http://example.net/index.html#text1">Some Text</textPath>
页面不工作,子页面不工作
我还有 <base href="http://example.net">
设置在 index.html 头部。
那么如何使用 hashbang href 方式将文本路径与 SVG 连接起来。
还有当前的htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php [L,QSA]
我现在想到的一个想法是设置 window.location.pathname="/"
但不幸的是,该页面现在一直在重新加载。因此,即使使用另一个 URL 也没有真正解决问题,但告诉他一个不同的 URL。
这里还有非常有趣的文档:http://www.w3.org/TR/SVG/linking.html但无法从中找到解决方案。
最佳答案
这个工作正常:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(?:css|js|maps|pics) [NC]
RewriteRule (/(?:css|js|maps|pics)/.*)$ $1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.html [L]
因此,在 htaccess 中而不是在 index.html 中重写基础是可行的方法。上面的附加重写规则确保您仍然可以在 example.net/about/creator 上找到正确的 css 和 so 文件。
关于javascript - 在子站点/子文件夹中找不到 SVG href ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28605609/