[英]block url direct access to index.php except when user clicked on the link on another specific html file such as index.html
首先,对不起我的英语
我想限制对Wordpress中index.php文件的直接访问,例如当用户在URL栏中键入www.example.com/index.php时。
我只希望在用户查看index.html上的index.html时打开该文件,我使用JAVASCRIPT在几秒钟后重定向到index.php
这可能应该通过通过.htaccess文件进行mod重写来完成。假设您的Web服务器已安装,(大多数情况下)..创建或编辑.htaccess文件
RewriteEngine On
# If not from
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/index\.html [NC]
# Go to
RewriteRule .* http://example.com/index.html [L]
请注意,HTTP_REFERER是查看器浏览器提供的值,并且可以被欺骗和/或编辑,因此并非100%可靠
您可以在index.php上使用一些PHP代码
if($_SERVER['HTTP_REFERER'] != 'www.example.com/index.html')
{
header("location: www.example.com/some_page.php");
die();
}
这段代码基本上是说如果您之前位于isnt index.html
之前的页面,然后重定向到其他页面,您可以使用一点点PHP知识就可以根据需要进一步对其进行自定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.