【问题标题】:how to rename URL with htaccess without affecting on the relative links in the page如何在不影响页面中的相对链接的情况下使用 htaccess 重命名 URL
【发布时间】:2015-10-05 05:12:44
【问题描述】:

我尝试在 htaccess 文件中添加这个表达式

footerrelated   ^help/([A-Za-z0-9-]+)/?$    index.php?requestedPage=footerrelated&page=$1 [NC,L]

所以当用户输入类似的链接时

http://localhost/askRondWebsite/public_html/footerrelated/helpcenter

应该返回

http://localhost/askRondWebsite/public_html/index.php?requestedPage=footerrelated&page=helpcenter

但这会导致页面中的相对链接出现问题。

例如,在我的页面中,我有以下link 标签

<link rel="stylesheet" type="text/css" href="css/fotterrelated.css">

指的是http://localhost/askRondWebsite/public_html/css/fotterrelated.css

但是当我添加htaccess 表达式时,链接指向http://localhost/askRondWebsite/public_html/fotterrelated/css/fotterrelated.css
即使在 public_html 文件夹中没有创建名为 fotterrelated 的文件夹时,我网站中的所有相对 URL 也会发生这种情况。

为什么会这样?在添加 htaccess 表达式之前,我应该怎么做才能保持相对 URL 不变?

【问题讨论】:

标签: html .htaccess url


【解决方案1】:

您可以在页面 HTML 的 &lt;head&gt; 部分添加此内容:

<base href="/askRondWebsite/public_html/" />

这样每个相对 URL 都是从该基本 URL 而非当前页面的 URL 解析的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 2016-10-20
    • 2012-01-19
    • 2020-02-23
    相关资源
    最近更新 更多