簡體   English   中英

我如何建立一個網站,以便當用戶輸入與該網站相關的任何URL時,它會打開索引頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM