.htaccess RewriteRule:两个域使用相同的服务器和目录 [英] .htaccess RewriteRule: two domains using same server and directory
问题描述
作为一点背景知识,我们有两个域:
As a bit of background, we have two domains:
- mydomain.com
- mydomain.cz
mydomain.cz 指向 mydomain.com 的服务器并使用相同的目录.我们在 .htaccess(两个域共享)中有一个 RewriteRule,如下所示:
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
此 RewriteRule 在使用来自 mydomain.com/project.php?id=1(例如)和 mydomain 的内容时显示 mydomain.com/1.cz/1 还为内容拉取 mydomain.com/project.php?id=1.但是,我希望任何 mydomain.cz/(insert id here)'s 从 project_cz.php?id=(insert id here) 中提取内容,而不是显示服务器的域,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 指令,它定义了以下RewriteRule的条件.
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 RewriteRule:两个域使用相同的服务器和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!