问题描述
作为一个一点背景,我们有两个域:
As a bit of background, we have two domains:
- mydomain.com
- mydomain.cz
- mydomain.com
- mydomain.cz
mydomain.cz 点为 mydomain.com 的服务器,并使用相同的目录。我们在.htaccess一个重写规则(这两个领域的份额),如下所示:
mydomain.cz points to mydomain.com's server and uses the same directory. We have a RewriteRule in .htaccess (which both domains share) as follows:
RewriteRule ^([0-9]+)/?$ project.php?id=$1 [NC,L] # Handle project requests
RewriteRule ^([0-9]+)/?$ project_cz.php?id=$1 [NC,L] # Handle project requests
该重写规则显示的 mydomain.com/1 ,而使用从 mydomain.com/project.php?id=1 (例如)和 MYDOMAIN内容。 CZ / 1 也拉 mydomain.com/project.php?id=1 的内容。不过,我想任何 mydomain.cz/(插入ID在这里)的可以从 project_cz.php?ID =(插入ID这里)拉内容而不是显示服务器的域名,mydomain.com - ?任何想法
This RewriteRule shows mydomain.com/1 while using content from mydomain.com/project.php?id=1 (for example) and mydomain.cz/1 also pulls mydomain.com/project.php?id=1 for content. However, I would like any mydomain.cz/(insert id here)'s to pull content from project_cz.php?id=(insert id here) rather than displaying the server's domain, mydomain.com - any ideas?
例如: mydomain.cz/1 会使用 mydomain.com/project_cz.php?id=1 和 mydomain.com/1 将使用 mydomain.com/project.php?id=1
For example: mydomain.cz/1 would use mydomain.com/project_cz.php?id=1 and mydomain.com/1 would use mydomain.com/project.php?id=1
非常感谢。
推荐答案
添加一个的RewriteCond 指令,它定义了条件的下面的重写规则。
Add a RewriteCond directive, which defines the conditions for the following RewriteRule.
因此,例如:
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^([0-9]+)/?$ project.php?id=$1 [NC,L] # Handle project requests
RewriteCond %{HTTP_HOST} ^mydomain\.cz
RewriteRule ^([0-9]+)/?$ project_cz.php?id=$1 [NC,L] # Handle project requests
这篇关于htaccess的重写规则:使用同一台服务器和目录两个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!