【问题标题】:htaccess issue on codeigniter setup on ubuntuubuntu上codeigniter设置的htaccess问题
【发布时间】:2016-08-25 09:38:50
【问题描述】:
    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.

这是我为 abc.com 上传到服务器上的域和子域的 conf 文件。

    <!-- 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 admin@abc.com
      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 的 conf 文件

<!-- 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 admin@abc.com
  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>

如果上述配置文件有助于确定问题,请告诉我们,期待您的回复。

【问题讨论】:

    标签: apache .htaccess codeigniter ubuntu


    【解决方案1】:

    您的虚拟主机配置是否正确配置?

    如果可以的话,我建议您使用配置文件而不是 .htaccess。

    (在:/etc/apache2/sites-enabledsites-available,如果尚未激活) p>

    <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 admins@email.com
            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
    

    希望对你有帮助。

    【讨论】:

    • 我已经有两个用于 abc.com 和 admin.abc.com 的 conf 文件,它们都指向各自的根目录。不知道为什么会这样,这几天一直在苦苦挣扎。
    • 你能把这两个 .config 文件贴在我可以看的地方吗?如果您有 .config 文件,为什么还要使用 .htaccess?
    • 我已经添加了上面的文件,请您检查一下。我正在使用 htaac​​cess coz 将所有 http 重定向到 https
    • 在第一个 .config 文件中,尝试将 ServerName 设置为 www.abc.com
    • 我试过它不工作..!!!还有一些桌面它重定向到 www,但在某些桌面上它没有。可能是什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 2013-10-14
    • 2015-09-01
    • 2011-08-27
    • 1970-01-01
    相关资源
    最近更新 更多