1

有没有办法重写我网站上出站链接的 URL?我希望 .htaccess 将是唯一的答案。无法手动更改链接。

我需要将所有链接重定向http://www.example.comhttp://www.anothersite.com甚至是自定义错误文件。目的是阻止指向单个域的出站链接,无论是通过重定向还是简单地为它们提供错误页面。

先谢谢了!

4

2 回答 2

2

The aim is to block outbound links to one single domain whether it is by redirection or simply serving them an error page.

重定向确实是可能的。将此代码放入您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://www.anothersite.com%{REQUEST_URI} [L,NC,R=301]
于 2013-11-04T16:28:48.027 回答
0

As correctly written by CBroe as a comment above:

Nope, mod_rewrite works once a request has reached your server – which a request to http://www.google.com/ (assuming that’s one of your outbound links you don’t want) will never do.

To elaborate further, .htaccess only applies when people are visiting the website. This does not apply to outbound links and thus will not be able to have any effect.

The only way this could be done is through modifying the html output on the server side before it is given to the user, for example, you could remove all unwanted links on any text retrieved from a database prior to serving it to the user.

于 2017-11-20T11:21:03.207 回答