在 .htaccess 中使用 mod_rewrite 时,相对路径会在 HTML 中中断
我是 .htaccess
和 mod_rewrite 的新手。
我正在使用以下重写规则:
RewriteRule ^wants/([0-9]+)$ /wantlist.php?wantid=$1
RewriteRule ^dashboard$ /dashboard.php
我能够成功重定向这两种情况。
但为了做到这一点,我必须将 CSS、JS 和其他路径更改为绝对路径,否则 CSS 和 JS 将无法加载。
我使用了
<script type="javascript" src="js/javascript.js"></script>
在重写规则不起作用之后,
<script type="javascript" src="http://example.com/js/javascript.js"></script>
which,在我将其更改为后,我让它工作了。
网站上的任何其他 URL 也会发生同样的情况。
有没有办法绕过这个问题,因为我在正在开发的网站中几乎所有地方都使用相对路径?
I am new to .htaccess
and mod_rewrite.
I am using the following rewrite rules:
RewriteRule ^wants/([0-9]+)$ /wantlist.php?wantid=$1
RewriteRule ^dashboard$ /dashboard.php
I am able to successfully redirect both the cases.
But in order to do this, I had to change the CSS, JS and other paths to absolute paths without which the CSS and JS did not load.
I was using
<script type="javascript" src="js/javascript.js"></script>
which after the rewrite rule did not work and after I changed it to
<script type="javascript" src="http://example.com/js/javascript.js"></script>
I got it to work.
The same is happening for any of the other URLs on the website.
Is there a way to bypass this as I am using relative paths almost everywhere in the site I am developing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 URL 解析问题。 请参阅需要 mod_rewrite URL 信息
您可以使用
BASE
HTML 元素,用于例子:This is an URL resolving issue. See mod_rewrite URL info required
You could explicitly set a base URI with the
BASE
HTML element, for example: