[英].htaccess rewrite rules for multiple sites
I have 3 domain names: 我有3个域名:
I want to host all of them in one web hosting with the following directories: 我想将它们全部托管在一个具有以下目录的网络托管中:
All of them are linked to the same hosting server with A record. 所有这些都通过A记录链接到同一台托管服务器。
However, my hosting do not support virtual host. 但是,我的主机不支持虚拟主机。
I need .htaccess files to rewrite the URLs 我需要.htaccess文件来重写URL
So, I tried in this way: 因此,我以这种方式尝试:
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]
Thus, if I go to www.hellokitty.com, it rewrites to ./htdocs/hellokitty.com/ internally. 因此,如果我访问www.hellokitty.com,它将在内部重写为./htdocs/hellokitty.com/。
If I go to www.hellokitty.com/hellokitty.com/ 如果我访问www.hellokitty.com/hellokitty.com/
Or, if I go to www.hellokitty.com/keroro.com/ , it still works 或者,如果我访问www.hellokitty.com/keroro.com/ ,它仍然有效
So, my problem is that how to prevent the client direct access the above real URLs and show a 404 error to them? 因此,我的问题是如何防止客户端直接访问上述真实URL并向其显示404错误?
Insert this rule just below RewriteEngine On
line: 将以下规则插入到
RewriteEngine On
下面:
RewriteCond %{THE_REQUEST} /(hellokitty|keroro)\.com [NC]
RewriteRule ^ - [F]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.