本地站点重定向到实时站点 [英] Local site redirecting to live site
问题描述
我正在尝试在本地设置我的网络文件以进行测试。我的文档文件夹中有站点文件。我已经安装了xampp,并设置了Apache以使用balloon.dev来打开我的本地网站。但是,当我尝试使用它时,balloon.dev将重定向到实时站点。我不确定为什么。
I'm trying to set up my web files locally for testing. I have my site files in my documents folder. I have xampp installed and have set up apache to use baseball.dev to bring up my local website. But when I try to use it, baseball.dev redirects to the live site. I'm not sure why.
我的httpd-vhosts文件:
My httpd-vhosts file:
<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文件包含网站文件的文件夹。我以为这可能是造成问题的原因,但是当我将其移动或注释掉时,它没有任何作用。这是该文件:
There is an htaccess file in the folder with the website files. I thought this might be causing the problem, but when I moved it or commented it out, it had no effect. Here is that file:
# 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/$1 [L,R=301]
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
# End of Apache Rewrite Rules
</IfModule>
推荐答案
以下几行引起了重定向:
The lines below are causing the redirect:
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/$1 [L,R=301]
因此, www.baseball.dev
将重定向到 www.baseballforbusypeople.com
。
在开发服务器上,注释以上各行,并在生产服务器上保留它们的注释。
On your dev server, comment the above lines and leave them uncommented on your production server.
此外,请确保清除浏览器缓存仍然遇到重定向。
Also, be sure to clear your browser cache if you are still experiencing the redirect.
这篇关于本地站点重定向到实时站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!