本地站点重定向到实时站点
Local site redirecting to live site
我正在尝试在本地设置我的 Web 文件以进行测试。我的文档文件夹中有我的站点文件。我安装了 xampp 并设置了 apache 以使用 baseball.dev 打开我的本地网站。但是当我尝试使用它时,baseball.dev 重定向到实时站点。我不确定为什么。
我的 httpd-vhosts 文件:
<VirtualHost *:80>
DocumentRoot "C:/Users/Kirst/Documents/GitHub/baseball-for-busy- people/"
ServerName baseball.dev
ServerAlias www.baseball.dev
<Directory "C:/Users/Kirst/Documents/GitHub/baseball-for-busy-people/">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
我的主机文件:
127.0.0.1 www.baseball.dev
在网站文件所在的文件夹中有一个 htaccess 文件。我认为这可能是导致问题的原因,但是当我移动它或将其注释掉时,它没有任何效果。这是该文件:
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# Rewrite baseballforbusypeople.com as www.baseballforbusypeople.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/ [L,R=301]
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ / [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ .php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ .html
# End of Apache Rewrite Rules
</IfModule>
显而易见的首选是在 windows 上使用 ipconfig /flushdns
刷新 DNS。您是否确认主机名 www.baseball.dev 确实指向 127.0.0.1
我还注意到 htaccess 文件包含以下指令:RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
据我所知,这会将对包含 .htaccess 的站点的任何请求重写到 www.baseballforbusypeople.com 我猜是实时站点。
以下行导致重定向:
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/ [L,R=301]
因此,对 www.baseball.dev
的请求将重定向到 www.baseballforbusypeople.com
。
在您的开发服务器上,对以上行进行注释,并在您的生产服务器上不对它们进行注释。
此外,如果您仍然遇到重定向,请务必清除浏览器缓存。
我正在尝试在本地设置我的 Web 文件以进行测试。我的文档文件夹中有我的站点文件。我安装了 xampp 并设置了 apache 以使用 baseball.dev 打开我的本地网站。但是当我尝试使用它时,baseball.dev 重定向到实时站点。我不确定为什么。
我的 httpd-vhosts 文件:
<VirtualHost *:80>
DocumentRoot "C:/Users/Kirst/Documents/GitHub/baseball-for-busy- people/"
ServerName baseball.dev
ServerAlias www.baseball.dev
<Directory "C:/Users/Kirst/Documents/GitHub/baseball-for-busy-people/">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
我的主机文件:
127.0.0.1 www.baseball.dev
在网站文件所在的文件夹中有一个 htaccess 文件。我认为这可能是导致问题的原因,但是当我移动它或将其注释掉时,它没有任何效果。这是该文件:
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# Rewrite baseballforbusypeople.com as www.baseballforbusypeople.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/ [L,R=301]
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ / [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ .php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ .html
# End of Apache Rewrite Rules
</IfModule>
显而易见的首选是在 windows 上使用 ipconfig /flushdns
刷新 DNS。您是否确认主机名 www.baseball.dev 确实指向 127.0.0.1
我还注意到 htaccess 文件包含以下指令:RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
据我所知,这会将对包含 .htaccess 的站点的任何请求重写到 www.baseballforbusypeople.com 我猜是实时站点。
以下行导致重定向:
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/ [L,R=301]
因此,对 www.baseball.dev
的请求将重定向到 www.baseballforbusypeople.com
。
在您的开发服务器上,对以上行进行注释,并在您的生产服务器上不对它们进行注释。
此外,如果您仍然遇到重定向,请务必清除浏览器缓存。