【问题标题】:Stop localhost auto redirecting to https with the addition of www通过添加 www 停止 localhost 自动重定向到 https
【发布时间】:2020-03-16 08:43:46
【问题描述】:

在我的本地主机“http://subdomain.customdomain.com”上配置的网站正在重定向到“https://www.subdomain.customdomain.com”,我不知道为什么。

我所做的如下:

  1. 在 dyn.com 上设置主机名,即 subdomain.dyndns.org
  2. 设置路由器以将动态 IP 更新到 dyn.com 上的 subdomain.dyndns.org(路由器正在正确更新 IP)
  3. 由于我想使用自定义域,为 subdomain.customdomain.com 添加了 CNAME 记录,指向 subdomain.dyndns.org(这将解析到正确的 IP)
  4. 在我的路由器上的端口 80 上设置端口转发(外部 80 到内部 80)
  5. 在我的本地 apache 上设置虚拟主机:

     <VirtualHost subdomain.customdomain.com:80>
        DocumentRoot "C:/xampp/htdocs/customdomain"
        ServerName subdomain.customdomain.com:80
        ServerAlias subdomain.customdomain.com:80
    </VirtualHost>
    

现在,当我在浏览器中打开 http://subdomain.customdomain.com 时,它会重定向到 https://www.subdomain.customdomain.com 并出现错误:无法访问此站点 www.subdomain.customdomain.com 的服务器 IP 地址找不到。

当我在 Windows 主机文件中直接添加 subdomain.customdomain.com 以指向我的 LAN IP 时,它不会重定向并且网站工作正常。 就是想不通怎么回事?

以下是 .htaccess 文件内容:

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

<FilesMatch "\.(?i:pdf)$">
    ForceType application/pdf
    Header set Content-Disposition attachment
</FilesMatch>

【问题讨论】:

  • 您拥有 customdomain.com(我的意思是,无论它代表什么),并在您注册域的 DNS 管理中添加了 CNAME?我认为这是浏览器在 www 前面添加了一个。在它无法解析 subdomain.customdomain.com 的地址后到您的域。根据您设置 CNAME 的时间,可能需要数小时或数天才能传播到某些 DNS 服务器。
  • 是的,我拥有该域,它正在解析到正确的 IP 地址。我使用 dnschecker.org 进行了检查。奇怪的是,即使我直接在浏览器中打开我的公共 IP 地址,它也会重定向到“ https : // www .27.27.27.27/ ”(使用假 IP 进行描述)。所以问题似乎定位在路由器或本地服务器上。

标签: wordpress apache .htaccess localhost portforwarding


【解决方案1】:

已解决问题!问题出在虚拟主机配置上。

导致问题的配置

<VirtualHost *:80> 
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs/">
    AllowOverride All
    Require local
</Directory>
</VirtualHost>

<VirtualHost subdomain.customdomain.com:80>
DocumentRoot "C:/xampp/htdocs/some/directory/wordpress"
ServerName subdomain.customdomain.com:80
ServerAlias subdomain.customdomain.com:80
</VirtualHost> 

<VirtualHost www.somedomain.com:80>
DocumentRoot "C:/xampp/some/directory2/wordpress"
ServerName www.somedomain.com:80
ServerAlias somedomain.com:80
</VirtualHost> 

修复它的配置:

<VirtualHost *:80> 
ServerName localhost
ServerAlias localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>

<VirtualHost *:80>
ServerName subdomain.customdomain.com:80
ServerAlias subdomain.customdomain.com:80
DocumentRoot "C:/xampp/htdocs/some/directory/wordpress"
</VirtualHost> 

<VirtualHost  *:80>
DocumentRoot "C:/xampp/some/directory2/wordpress"
ServerName www.somedomain.com:80
ServerAlias somedomain.com:80
</VirtualHost> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-01
    • 2017-09-02
    • 2016-07-19
    • 2020-05-29
    • 2020-03-06
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    相关资源
    最近更新 更多