2015-10-22 48 views
2

我的網站有文檔根〜/ public_html我試圖使用htaccess組織多域/子域重定向。miltiple域名/子域名使用htaccess

可能的重定向邏輯:如果發現域/子域目錄 - 執行重定向,否則拋出404錯誤。

可能的目錄結構:

public_html/ 
      .htaccess (main redirect router) 
public_html/ 
      domain-1/ 
        application/ 
        public_html/ 
           .htaccess 
public_html/ 
      domain-2/ 
        application/ 
        public_html/ 
           .htaccess 
public_html/ 
      domain-3/ 
        application/ 
        public_html/ 
           .htaccess 
public_html/ 
      subdomain-1.domain-1/ 
           application/ 
           public_html/ 
              .htaccess 
public_html/ 
      subdomain-2.domain-1/ 
           application/ 
           public_html/ 
              .htaccess 

你的幫助,深深讚賞。 謝謝。

+0

這就是VirtualHosts的優點。 https://httpd.apache.org/docs/2.2/en/vhosts/ – wmk

+0

不幸的是,根據我的主機限制,我無法訪問apache設置。 – mosgaz

+0

是否可以使用htaccess解決我的問題? – mosgaz

回答

0

.htaccess文件應該有

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^subdomain.domain.in [NC] 
RewriteRule ^(.*)$ http://www.hardikvyas.in/$1 [L,R=301] 

RedirectMatch ^/$ /redirection directory name/ 

試試這個。

+0

謝謝,Hardik Vyas!另一種方式來完成它: RewriteCond%{HTTP_HOST}^subdomain.domain.com RewriteRule ^(。*)$ http://domain.com/subdomain/$1 [L,NC,QSA] – mosgaz

+0

找到其他方法,沒有.htaccess涉及http://stackoverflow.com/questions/33277100/miltiple-domain-subdomain-using-htaccess?noredirect=1#comment54383405_33277100 – mosgaz

+0

歡迎朋友.. –