首页 文章

.htaccess从子域名的文章重定向到主域名而没有子域名更改

提问于
浏览
0

我有一个域名,www.example.com和子域名test.example.com . 当我调用test.example.com时,我需要将其重定向到www.example.com/search/property/test_state,而不更改test.example.com中的url . 所以网址应该只看起来像test.example.com .

我用.htaccess代码做了这个,比如

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule  ^$ /search/property/%1_state [P]

在此之后,当我访问子域名中的任何网址时,例如test.example.com/content/sell_your_home,它不应该将网址更改为主域名 . 目前,当我访问它时,它将重定向到主域 . 有任何想法吗?

1 回答

  • 0

    如果测试子域与主域具有相同的服务器根(文档根),则不需要 P 标志:

    RewriteCond %{REQUEST_URI} !^/index\.php$
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    RewriteCond %{HTTP_HOST} !^webmail\.example\.com
    RewriteCond %{HTTP_HOST} !^m\.example\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
    RewriteRule  ^$ /search/property/%1_state/ [L]
    

    否则,您需要完整的URL:

    RewriteCond %{REQUEST_URI} !^/index\.php$
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    RewriteCond %{HTTP_HOST} !^webmail\.example\.com
    RewriteCond %{HTTP_HOST} !^m\.example\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
    RewriteRule  ^$ http://www.example.com/search/property/%1_state/$1 [L,P]
    
    RewriteCond %{REQUEST_URI} !^/index\.php$
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    RewriteCond %{HTTP_HOST} !^webmail\.example\.com
    RewriteCond %{HTTP_HOST} !^m\.example\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
    RewriteRule  ^(.*)$ http://www.example.com/$1 [L,P]
    

相关问题