Yii2非https和www url重定向到前端/ web

时间:2017-04-17 09:42:57

标签: yii2 virtualhost

我在Yii2中面临关于URL的奇怪问题

当我访问myweb.com, www.myweb.com, http://myweb.com, https://myweb.com时,我被重定向到https://www.myweb.com/frontend/web并显示404错误。

但是当我访问https://www.myweb.com时,它正常工作,没有显示错误。

请帮我解决这个问题,我想这是因为虚拟主机或.htaccess配置在这里是我的虚拟主机

port 80 non https /etc/apache2/sites-available/myweb.com.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        ServerName myweb.com
        ServerAlias www.myweb.com

        DocumentRoot /var/www/html/myweb/frontend/web
        Redirect / https://myweb.com/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

这里是virtualhost https /etc/apache2/sites-available/http-myweb.com.conf

Listen 443
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        ServerName myweb.com
        ServerAlias www.myweb.com
        DocumentRoot /var/www/html/myweb/frontend/web

        SSLEngine On
        SSLCertificateFile "/home/jun/certificate.crt"
        SSLCertificateKeyFile "/home/jun/private.key"
        SSLCACertificateFile "/home/jun/ca_bundle.crt"

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

这是项目文件夹中的.htaccess

# prevent directory listings
Options -Indexes
IndexIgnore */*

# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^administrator(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1

RewriteCond %{HTTP_HOST} ^myweb\.com [NC]
RewriteRule ^(.*)$ https://www.myweb.com/$1 [L,R=301]

这里是前端/网络中的.htaccess

RewriteEngine on
# RewriteBase /frontend/web
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

这是我从inspect元素

获得的
General
Request URL:http://myweb.com/
Request Method:GET
Status Code:301 Moved Permanently (from disk cache)
Remote Address:123.231.250.140:80
Referrer Policy:no-referrer-when-downgrade

Response Headers
Content-Length:243
Content-Type:text/html; charset=iso-8859-1
Date:Mon, 17 Apr 2017 08:47:29 GMT
Location:https://www.myweb.com/frontend/web/
Server:Apache

那么我的代码或配置有什么问题?

提前感谢。

0 个答案:

没有答案