我可以在htaccess中修改锚标记href吗?

时间:2013-01-31 19:53:18

标签: php .htaccess

不确定这是否可行,但想知道htaccess是否有诀窍......

假设我有像这样的锚标记href -

<a href="http://example.com/index.php?id=12345">Click here</a>

我使用mod_rewrite更改了URL结构,但想知道我是否可以使用htaccess隐藏href中的实际URL。

即当用户将鼠标悬停在锚标记上时,浏览器会在底部显示http://example.com/index.php?id=12345。我希望浏览器显示的只是http://example.com/index/12345,而不是在我的所有页面上手动更改它。

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

为什么不将链接更改为以下内容?

<a href="http://example.com/index/12345">Click here</a>

由于您可以更改.htaccess,我希望您拥有或管理此域名。所以它应该是可能的。

如果链接是由PHP代码生成的,那么我建议您实现并使用如下的翻译功能:

function beautify($ugly) {
    // your logic comes here
    return $nice; // ;)
}

...并将其包装在当前输出网址的现有代码周围。这有两个好处:

  • 迁移到新网址方案很容易且更安全,
  • 从现在开始,您可以使用单一功能控制所有与网址相关的代码

答案 1 :(得分:0)

我同意,htaccess无法帮助你。我想你必须手动更改它们。 我希望我能得到更多的帮助

答案 2 :(得分:0)

没有。 htaccess用于处理Web服务器的输入,而不是从服务器发回的数据。

如果你使用jQuery,你可以在页面使用这样的东西加载时重写href。

$(function(){
    $("a").each(function() { 
      this.href = 'some_new_url that you made based on the one in this.href';
    });
});
相关问题