Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing this 301 redirect? [closed]

I have a problem with my server redirecting http://www.mylesgray.com:8080/ -> http://www.mylesgray.com/.

Here are my Nginx default and fastcgi_params config files:

https://gist.github.com/1745271

https://gist.github.com/1745313

This is rather a nusance as I am trying to run a benchmark of Nginx w/ caching vs Varnish w/ caching on top of Nginx to see if there is any performance benefit of one over the other.

As such I have straight Nginx w/ caching listening on port 8080 and varnish on port 80 which forwards any non-cached requests to Nginx on localhost:8080, so obviously what I want to do is run an ab benchmark on http://www.mylesgray.com:8080/ and on http://www.mylesgray.com/ to see the difference.

Here are the results of curl -I on various addresses.

# curl -I http://www.mylesgray.com:8080

HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Date: Sun, 05 Feb 2012 12:07:34 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1
X-Pingback: http://www.mylesgray.com/xmlrpc.php
Location: http://www.mylesgray.com/

# curl -I http://mylesgray.com

HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Content-Type: text/html; charset=UTF-8
X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1
X-Pingback: http://www.mylesgray.com/xmlrpc.php
Location: http://www.mylesgray.com/
Content-Length: 0
Date: Sun, 05 Feb 2012 12:15:51 GMT
X-Varnish: 1419774165 1419774163
Age: 15
Via: 1.1 varnish
Connection: keep-alive

# curl -I http://mylesgray.com:8080

HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Date: Sun, 05 Feb 2012 12:16:08 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1
X-Pingback: http://www.mylesgray.com/xmlrpc.php
Location: http://www.mylesgray.com/

Then running curl -I http://www.mylesgray.com gives:

# curl -I http://www.mylesgray.com

HTTP/1.1 200 OK
Server: nginx/0.7.65
Content-Type: text/html; charset=UTF-8
X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1
X-Pingback: http://www.mylesgray.com/xmlrpc.php
Content-Length: 5132
Date: Sun, 05 Feb 2012 12:07:29 GMT
X-Varnish: 1419774133 1419774124
Age: 30
Via: 1.1 varnish
Connection: keep-alive

So as you can see 80 is served by Varnish and 8080 by Nginx but I cannot find anywhere anything that does a 301 redirect, not in nginx.conf or in the sites-enabled/default file and I don't believe it is caused by Wordpress itself but an very much open to correction.

Please help, this is driving me nuts!

Myles

like image 756
Myles Gray Avatar asked Feb 05 '12 12:02

Myles Gray


People also ask

What is a 301 redirect?

What is a 301 redirect? Simply put, a 301 redirect is a type of URL redirection that involves the permanent redirection of one web page to another web page, preventing the user from ending up on a ‘ 404 Page Not Found page. It is usually done either through the use of plugins and themes or by adding a piece of code to the .htaccess file.

How long does it take for a 301 redirect to expire?

A permanent HTTP 301 usually redirects your site around a year or longer. After that, make sure you check to see if users are still being sent to your new URL. How do I fix 301 redirects?

What is a 302 redirect and how do I remove it?

302 redirects are only for temporary redirects and you should never use them for permanent moves. If you happen to have a 302 redirect for a permanent move, you should remove it or replace it with an HTTP response status code 301 Moved Permanently.

When should I use 301 status codes?

You should use 301 status codes when you're permanently replacing one URL for another. Meaning, you'll be redirecting both users and bots to the new URL. You: This page has moved permanently, and we don't plan on moving it back. Browser: Okay, got it.


1 Answers

You should add a '/' at then end of your URLs. Furthermore if you run ab http://foo.com it will return you a "ab: invalid URL" error. If you do "ab -t 10 http://example.com/" everything will work fine. You should always use '/' in your URLs otherwize your webserver will try to redirect the page to the home page automatically for you which generates an undesirable extra load on the server and some extra bytes on the wire.

You web server told you what it did:

'/' is missing and something is incorrect with the port numer:

# curl -I http://www.mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
======> Location: http://www.mylesgray.com/

'www' and '/' are missing:

# curl -I http://mylesgray.com
HTTP/1.1 301 Moved Permanently
[...]
=======> Location: http://www.mylesgray.com/
[...]

'/' and 'www' are missing:

# curl -I http://mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
========> Location: http://www.mylesgray.com/

'hope that helps :)

like image 158
Jérôme R Avatar answered Oct 02 '22 18:10

Jérôme R