簡體   English   中英

.htaccess多個站點的重寫規則

[英].htaccess rewrite rules for multiple sites

腳本

我有3個域名:

  1. www.hellokitty.com
  2. www.keroro.com
  3. www.doraemon.com

我想將它們全部托管在一個具有以下目錄的網絡托管中:

  1. ./htdocs/hellokitty.com/
  2. ./htdocs/keroro.com/
  3. ./htdocs/doraemon.com/

所有這些都通過A記錄鏈接到同一台托管服務器。

但是,我的主機不支持虛擬主機。

我需要.htaccess文件來重寫URL

因此,我以這種方式嘗試:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?hellokitty.com$ [NC]
RewriteCond %{REQUEST_URI} !^/hellokitty\.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /hellokitty\.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?hellokitty.com$ [NC]
RewriteRule ^(/)?$ hellokitty.com/index.php [L]

RewriteCond %{HTTP_HOST} ^(www.)?keroro.com$ [NC]
RewriteCond %{REQUEST_URI} !^/keroro\.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /keroro\.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?keroro.com$ [NC]
RewriteRule ^(/)?$ keroro.com/index.php [L]

RewriteCond %{HTTP_HOST} ^(www.)?doraemon.com$ [NC]
RewriteCond %{REQUEST_URI} !^/doraemon\.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /doraemon\.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?doraemon.com$ [NC]
RewriteRule ^(/)?$ doraemon.com/index.php [L]

因此,如果我訪問www.hellokitty.com,它將在內部重寫為./htdocs/hellokitty.com/。

問題

如果我訪問www.hellokitty.com/hellokitty.com/

或者,如果我訪問www.hellokitty.com/keroro.com/ ,它仍然有效

因此,我的問題是如何防止客戶端直接訪問上述真實URL並向其顯示404錯誤?

將以下規則插入到RewriteEngine On下面:

RewriteCond %{THE_REQUEST} /(hellokitty|keroro)\.com [NC]
RewriteRule ^ - [F]

暫無
暫無

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

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