簡體   English   中英

如何在不更改 url 的情況下將所有頁面請求重定向到一個頁面

[英]how to redirect all page request to one page without url change

我想將我網站上的所有頁面(包括索引)重定向到UnderWork.html ,我正在使用.htaccess和以下代碼執行此操作:

RewriteEngine on
RewriteRule ^(.*)$ UnderWork.html

...它的工作正常。 現在我向我的.htaccess添加更多代碼以將所有流量重定向到非 www 域,現在我的代碼如下所示:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.in
RewriteRule ^(.*)$ http://domain.in$1 [R=permanent,L]
RewriteRule ^(.*)$ UnderWork.html

這是我遇到問題的地方。 如果我輸入一個像: domain.in/xyz這樣的 URL,那么它會像以前一樣工作,但是如果我使用像這樣的 URL: www.domain.in/xyz然后 Apache 將它轉換為coincart.inxyz/

我在這里做錯了什么? 我怎樣才能得到我想要的? 提前致謝。

以下是對我有用的規則:

RewriteEngine On

# Adding trailing slash for directory requests.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/www$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.+[^/])$ http://example.com/$1/ [R=permanent]

# External redirection from www subdomain to non-www domain.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^/?(.*) http://example.com/$1 [L,R=permanent]

# Internal redirection to index.php for nonexistent URLs.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|png|gif)$
RewriteRule . /index.php [L,QSA]

要在請求目錄根(特別是域根)時顯示自定義頁面,請使用 Apache 的DirectoryIndex指令:

DirectoryIndex UnderWork.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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