2016-04-30 128 views
0
My website open properly when I type `www.abc.com` on browser but when I type `abc.com` it opens page of subdomain which I have hosted which is `admin.abc.com`. 

    But the url still says `abc.com` 

    Here is my .htaccess code: 

    <!-- language: lang-bash --> 

     RewriteEngine on 
     RewriteBase/
     RewriteCond %{HTTP_HOST} !^www\. [NC] 
     RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

    I am using Ubuntu 14.04 with Apache and have configured virtual hosts for both domains. 
    Any guidance will be highly appreciated. 

這是我的conf文件abc.com上傳到服務器上的域和子域。在Ubuntu上codeigniter安裝htaccess問題

<!-- language: lang-bash --> 
    # domain: abc.com 
    # public: /var/www/abc.com/public_html/ 

    <VirtualHost *:443> 
     SSLEngine On 
     SSLCertificateFile /etc/ssl/localcerts/c8d39f3574580de6.crt 
     SSLCertificateKeyFile /etc/ssl/localcerts/abc.key 
     SSLCertificateChainFile /etc/ssl/localcerts/gd_bundle-g2-g1.crt 

     <Directory /var/www> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     Order allow,deny 
     allow from all 
     </Directory> 

     # Admin email, Server Name (domain name), and any aliases 
     ServerAdmin [email protected] 
     ServerName abc.com 
     ServerAlias abc.com 

     # Index file and Document Root (where the public files are located) 
     DirectoryIndex index.html index.php 
     DocumentRoot /var/www/abc.com/public_html 
     # Log file locations 
     LogLevel warn 
     ErrorLog /var/www/abc.com/log/error.log 
     CustomLog /var/www/abc.com/log/access.log Combined 
    </VirtualHost> 

這裏是admin.abc.com

<!-- language: lang-bash --> 

# domain: admin.abc.com 
# public: /var/www/admin.abc.com/public_html/ 

<VirtualHost *:80> 
    # Admin email, Server Name (domain name), and any aliases 
    ServerAdmin [email protected] 
    ServerName admin.abc.com 
    ServerAlias admin.abc.com 

    # Index file and Document Root (where the public files are located) 
    DirectoryIndex index.html index.php 
    DocumentRoot /var/www/admin.abc.com/public_html 
    # Log file locations 
    LogLevel warn 
    ErrorLog /var/www/admin.abc.com/log/error.log 
    CustomLog /var/www/admin.abc.com/log/access.log combined 
</VirtualHost> 

我的conf文件確實讓我們知道,如果上述的conf文件,其中有助於確定問題,期待您的回覆。

回答

0

您是否正確配置了虛擬主機配置?

如果您能夠,我會推薦您使用配置文件而不是.htaccess。

(下:的/ etc/apache2的/啓用的站點 -網站可用,如果尚未激活)

<VirtualHost *:80> 

     # With this configuration when you try to reach both www.abc.com 
     # and abc.com it directs you to the same place. 
     # If you got a subdomain, you should create a separate .conf file 
     # with the correct configurations as well. 

     ServerAdmin [email protected] 
     ServerName www.abc.com 
     ServerAlias abc.com 
     DocumentRoot /var/www/path/to/websites/folder 

     # Some more comments... 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

     # More comments... 
</VirtualHost> 

編輯在此之後,不要忘記重啓Apache服務器:

sudo service apache2 restart 

sudo systemctl restart apache2.service 

希望它有幫助。

+0

我已經有兩個conf文件同時用於abc.com和admin.abc.com ,它們都指向它們各自的根目錄。不知道爲什麼它發生,現在正在掙扎幾天。 – user3637820

+0

你可以發佈這兩個.config文件的地方我可以看看它嗎?如果你有一個.config文件,你爲什麼使用.htaccess? –

+0

我已添加上面的文件,你可以請檢查。我使用htaac​​cess因爲重定向所有HTTP到https – user3637820