2016-08-23 132 views
-2

例如,我有一个网站example.com,它链接到example.org中存储的文件。因此,如果用户点击下载(默认链接是www.example.org/file.zip),我想将他重定向到第三个域 - example.net。简而言之: www.example.com已链接到www.example.org,但当您单击它时,您将被重定向到example.net。这可能使用htaccess?如何使用htaccess重定向链接?

回答

0

回答你的问题:是的,这是可能的。您的含义很模糊,因此您需要确保自定义以下解决方案以满足您的真实需求。但重要的它会是这样的:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)\.zip$ http://example.com/{REQUEST_URI} [L,QSA] 
</IfModule> 
+0

我的意思是,如果我加入www.example.com像这样的链接:到 File我想重定向example.org/file.zip www.example.net – cooher

+0

是的,这正是.htaccess的用途。 [htaccess手册](https://httpd.apache.org/docs/current/howto/htaccess.html) – mrheroux

+0

好吧,我知道我非常含糊,因为我的第一语言不是英语。我找到了我想要的: AddOutputFilterByType SUBSTITUTE text/html 替代s/mysite.com/sitename.com/ni 现在我需要将geoIP应用于此代码。我试图这样做: SetEnvIf之后GEOIP_COUNTRY_CODE美国LinkCountry 这里 #Substitute但它不工作。没有IfDefine的替代代码完美工作,geoIP也很好(我已经用env = LinkCountry的拒绝测试了它)。任何想法如何使用If语句? – cooher