【发布时间】:2011-04-21 00:40:08
【问题描述】:
我有同一个网站的两个域。
我的网站上有一个页面,我希望它看起来来自第二个域(在本例中为 example2.com/pagex)。除了 root 和 pagex,所有其他对 example2.com 的请求都应重定向到 example1.com。
由于下面显示的 mod_rewrite 规则,我网站上的所有页面都显示为目录,但实际上只是 index.php?page=pagename。
这是我的 .htaccess 文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteCond %{REQUEST_URI} !^/$ #Do not redirect root
RewriteCond %{REQUEST_URI} !^/pagex/ #Do not redirect pagex
RewriteRule ^(.*)$ http://www.example1.com/$1 [R=301]
# If the file or folder does not exist, send to index.php as variable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
通过转到 example2.com/pagex/ 运行上述代码,我会被重定向到 www.example1.com/index.php?page=pagex。第二个条件应该失败,阻止重定向。更奇怪的是虚拟目录被实际路径替换了。
【问题讨论】:
-
那么,
/pagex/是一个实际存在的目录吗? -
/pagex/不是实际目录。index.php?page=pagex被屏蔽了。
标签: apache .htaccess mod-rewrite