我有一个子域名(称为subdomain.mydomain.com)
我只想要一个页面(例如:www.mydomain.com/page1.php)重定向到我的子域
因此,当我加载subdomain.mydomain.com时,我想访问www.mydomain.com/page1.php但保留我的子域名 使用htacess或virtualhost 这是我编辑的代码及其评论Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mysite\.fr$ [NC]
RewriteRule ^index\.php/?$ http://apropos.mysite.fr/? [NC,L,R]
RewriteCond %{HTTP_HOST} ^apropos\.mysite\.fr$ [NC]
RewriteRule ^$ http://www.mysite.fr/index.php?com=who [L,P,QSA]
答案 0 :(得分:1)
因此,当我加载subdomain.mydomain.com时,我想访问www.mydomain.com/page1.php但保留我的子域名
尝试将以下内容放在.htaccess的根目录中。我假设您的子域和域共享相同的根。
RewriteEngine on
RewriteBase /
# page (ex: www.mydomain.com/page1.php) redirects to my subdomain
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#do not redirect if from proxy
RewriteCond %{QUERY_STRING} !(^|&)r=1(&|$) [NC]
RewriteRule ^page1\.php/?$ http://subdomain.mydomain.com [NC,L,R=301]
#if subdomain.mydomain.com
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
#and root directory, then proxy to page1
RewriteRule ^$ http://www.mydomain.com/page1.php?r=1 [P,L]
答案 1 :(得分:1)
您可以在ROOT .htaccess中尝试以下代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
# Redirects www.mydomain.com/page1.php?com=who to subdomain.mydomain.com
RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^page\.php/?$ http://subdomain.mydomain.com/? [NC,L,R]
# Internal Redirect(Proxy) subdomain.mydomain.com to www.mydomain.com/page1.php?com=who
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^$ http://www.mydomain.com/page.php?com=who [L,P,QSA]