【发布时间】:2015-06-29 15:31:31
【问题描述】:
我需要防止直接访问 URL (http://www.example.com/gated-asset)。有没有办法向 htaccess 文件添加代码,将所有直接流量重定向到另一个页面 (http://www.example.com/form)?
我在我的 htaccess 文件中尝试了以下代码,但所有页面,包括主页,都重定向到 www.example.com/form。
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://go.example.com [NC]
RewriteRule .* http://www.example.com/form [R,L]
整个 .htaccess 文件如下所示(它是一个 WordPress 网站):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://go.example.com [NC]
RewriteRule .* http://www.example.com/form [R,L]
我还尝试了以下方法:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://go.example.com [NC]
RewriteRule ^/$ /form/ [R,L]
RewriteRule ^/$ /gated-asset/ [R,L]
还有:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://go.example.com [NC]
RewriteRule http://www.example.com/gated-asset http://www.example.com/form/ [R,L]
【问题讨论】: