I am setting up a development environment with XAMPP on Windows. Apache version is 2.4.17.
My development url is www.hagertyforjudge.dev, also accessible at hagertyforjudge.dev. I am trying to solve a mystery about getting a 301 redirect when I don't think I've set up anything on the server side that would call for it.
Here are the relevant lines from httpd-vhosts.conf
:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "H:/xampp2015/htdocs/hfj.dev"
ServerName www.hagertyforjudge.dev
ServerAlias hagertyforjudge.dev
<Directory "H:/xampp2015/htdocs/hfj.dev">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
I have not changed the default setting for UseCanonicalName
, so it should be off
(though it shouldn't matter, I don't think, for my issue).
There is no .htaccess file in the site directory.
Here are the lines from my hosts file that enable me to access this fake site in my browser:
127.0.0.1 hagertyforjudge.dev
127.0.0.1 www.hagertyforjudge.dev
I can access the site fine with any browser (both at hagertyforjudge.dev and at www.hagertyforjudge.dev), and in fact I was able to set up WordPress. I did so by visiting www.hagertyforjudge.dev. That URL got baked into the WordPress database (as 'site_url' and 'home' in the 'options' table). So far so good.
Here's what I don't understand: If I visit hagertyforjudge.dev
in my browser, I get a 301 redirect to www.hagertyforjudge.dev
. Here is all of the request and response information, according to FireFox's dev tools (Chrome's dev tools give the same info):
Request URL: http://hagertyforjudge.dev/
Requet method: GET
Remote address: 127.0.0.1:80
Status Code: 301 Moved Permanently
Version: HTTP/1.1
Request headers:
Host: hagertyforjudge.dev
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_8b3181539def2da5a4654e12bb9d4938=bhagerty%7C1455596780%7C662a3e414d01c0b773a41027df5f3da8; wp-settings-time-1=1455423988
Connection: keep-alive
Response headers:
Connection: Keep-Alive
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Sun, 14 Feb 2016 04:34:24 GMT
Keep-Alive: timeout=5, max=100
Location: http://www.hagertyforjudge.dev/
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.14
X-Pingback: http://www.hagertyforjudge.dev/xmlrpc.php
X-Powered-By: PHP/5.6.14
I did not tell Apache to do a 301 redirect. (Per this guy's discussion of redirection, the ServerAlias setting in the VirtualHost file is internal to Apache and does not generate a 301 or 302 redirect). I don't have an .htaccess file that would cause a 301 redirect.
So How can a 301 redirect be happening? It has to come from Apache, right? But I don't think I've set up a 301 redirect in Apache. I really appreciate any insight you might have.
Doesn't WP create an .htaccess file?
Yes, it does however it should be noted only if the directory is writable, and you 'MUST' trigger it by setting up permalinks.