问题
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.
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>
My hosts file:
127.0.0.1 www.baseball.dev
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>
回答1:
The lines below are causing the redirect:
RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
RewriteRule ^(.*)$ http://www.baseballforbusypeople.com/$1 [L,R=301]
As such, requests to www.baseball.dev
will redirect to 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.
回答2:
The obvious first choice would be to flushdns using ipconfig /flushdns
on windows. Have you confirmed that the hostname www.baseball.dev does indeed point to 127.0.0.1
Also I have noticed that the htaccess file contains the following directive: RewriteCond %{HTTP_HOST} !^www.baseballforbusypeople.com$ [NC]
as far as my knowledge stretches that would rewrite any request for the site that the .htaccess is contained in to the www.baseballforbusypeople.com site which I'm guessing is the live site.
来源:https://stackoverflow.com/questions/30425313/local-site-redirecting-to-live-site