简体   繁体   English

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

[英]Can I modify anchor tag href in htaccess?

Not sure if this is possible but wanted to know if htaccess has a trick... 不知道这是否可能,但想知道htaccess是否有窍门...

Say I have anchor tag href like this - 假设我有这样的锚标签href-

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

I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess. 我已经使用mod_rewrite更改了URL结构,但想知道我是否可以使用htaccess在href中隐藏实际的URL。

ie when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. 例如,当用户将鼠标悬停在锚标记上时,浏览器在底部显示http://example.com/index.php?id=12345 All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages. 我只希望浏览器显示的是http://example.com/index/12345,而无需在我的所有页面上手动更改它。

Thanks for the help ! 谢谢您的帮助 !

Why don't you change the link to the following? 为什么不将链接更改为以下内容?

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

As you can change the .htaccess I expect that you own or adminstrate this domain. 当您可以更改.htaccess时,我希望您拥有或管理此域。 So it should be possible. 因此应该有可能。

If the links are generated by PHP code, then I suggest you to implement and use a translation function like: 如果链接是由PHP代码生成的,那么我建议您实现并使用翻译功能,例如:

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

... and wrap it around the existing code that currently outputs the urls. ...并将其包装在当前输出网址的现有代码周围。 This would have two advantages: 这将具有两个优点:

  • It's easy and more failsafe to migrate to the new url scheme 迁移到新的url方案既简单又安全
  • From now on you have control over all url related code using a single function 从现在开始,您可以使用一个功能来控制所有与网址相关的代码

I agree, htaccess can't help you. 我同意,htaccess无法帮助您。 I guess you'll have to change them manually. 我猜您将不得不手动更改它们。 I wish I could be of more help 希望我能对您有所帮助

No. htaccess is for processing input to the web server, not data sent back from the server. 否htaccess是用于处理输入到Web服务器的输入,而不是用于处理从服务器发送回的数据。

If you use jQuery you could have it rewrite the href when the page loads using something like this. 如果您使用jQuery,则可以在页面加载时使用类似方法重写href。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM