![](/img/trans.png)
[英]Is there any way to delete the URL address whenever a user enters my website?
[英]How can I make a website such that when a user enters any URL related to the website, it opens up the index page
让我们假设我有一个静态HTML网站“ example.com/index.html”,而另一个页面的URL为“ example.com/contact-us.html”。
当某人想直接进入contact-us.html页面时,在浏览器中输入URL“ example.com/contact-us.html”。 但是我想在这种情况下打开索引页面。 但是,一旦将网站加载到带有索引页面的浏览器中,用户就必须能够根据自己的意愿浏览网站上的链接。
这可能吗 ? 如果是,怎么办?
如果要阻止用户直接打开除索引之外的页面,则可以检查引荐来源网址,如果引荐来源网址与您的网站不匹配,则可以重定向到索引页面。
您在使用Apache吗? 如果是这样,可以使用mod_rewrite来执行此操作。
首先,通常通过在httpd.conf
文件中取消注释以下行来启用mod_rewrite:
LoadModule rewrite_module modules/mod_rewrite.so
然后在与index.html
相同的文件夹中创建一个.htaccess
文件,其内容如下:
RewriteEngine on
RewriteRule ^index.html$ index.html [QSA,L]
RewriteCond %{HTTP_REFERER} !^http://example\.com/.*$
RewriteRule ^.*$ /index.html [R,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.