.htaccess RewriteRule: two domains using same server and directory

泄露秘密 提交于 2019-11-27 04:43:40

问题


As a bit of background, we have two domains:

  1. mydomain.com
  2. mydomain.cz

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

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?

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

Many thanks.


回答1:


Add a RewriteCond directive, which defines the conditions for the following RewriteRule.

So for example:

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


来源:https://stackoverflow.com/questions/6972413/htaccess-rewriterule-two-domains-using-same-server-and-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!