http redirect shows a 302 but should be 301 - iis

I have a site that uses SSL.
When I correct to the default (http://www.example.com), it supposed to load http://www.example.com
And it does, but when I use a redirect checker, I notice this:
www.accufinance.com
HTTP/1.1 302 Found
Cache-Control: private,no-transform
Content-Type: text/html; charset=utf-8
Location: https://www.accufinance.com/
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 18 Sep 2014 00:20:43 GMT
Connection: close
Content-Length: 145
https://www.accufinance.com/
My site in on a shared host, so I used a web.config redirect.
In that, I have:
<action type="Rewrite" url="mypath/mysite/{R:1}" redirectType="Permanent"/>
Note: Since posing, I changed type="Rewrite" to type="Redirect", but no in the result. Still seems to be a 302.
So I am expecting a 301 - permanently moved, and, hoping not to see a "Not found".
What could be wrong here?

Related

Follow on 301 redirect using .htaccess

Wondered if someone can help me. I'm trying to remove a 302 redirect from one of my sites but I can't get the code correct. It works for the first http -> https but the redirect to /tt-rss/ is still being done using 302
This is what I'm using......can anyone help?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
>>> http://rss.oliroe.com
> --------------------------------------------
> 301 Moved Permanently
> --------------------------------------------
Status: 301 Moved Permanently
Code: 301
Server: nginx
Date: Wed, 05 Oct 2022 12:14:02 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 231
Connection: close
Location: https://rss.oliroe.com/
>>> https://rss.oliroe.com/
> --------------------------------------------
> 302 Found
> --------------------------------------------
Status: 302 Found
Code: 302
Server: nginx
Date: Wed, 05 Oct 2022 12:14:03 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/8.1.11
Location: /tt-rss/
Strict-Transport-Security: max-age=15768000; includeSubdomains; preload
>>> /tt-rss/
> --------------------------------------------
> 200 OK
> --------------------------------------------
Status: 200 OK
Code: 200
Server: nginx
Date: Wed, 05 Oct 2022 12:14:03 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/8.1.11
Cache-Control: public
Strict-Transport-Security: max-age=15768000; includeSubdomains; preload
I've solved this, the website had this code in the index.php header("Location: /tt-rss/");, I didn't realise redirects in php defaulted to 302. Changing the line to header("Location: /tt-rss/", true, 301); solved my issues. Many thanks

header code 302 beforer the 404 requested

I have a .htaccess file with several redirect rules and also this line :
ErrorDocument 404 https://www.mapaetmoi.fr/404.php
However when I type a url that does not exist such as https://www.mapaetmoi.fr/test/error, and I analyze the header, I have this:
URL: https://www.mapaetmoi.fr/test/error
HTTP / 1.1 302 Found
Date: Wed, 28 Jul 2021 14:25:28 GMT
Content-Type: text / html; charset = iso-8859-1
Connection: keep-alive
Server: Apache
Location: https://www.mapaetmoi.fr/404.php
HTTP / 1.1 404 Not Found
Date: Wed, 28 Jul 2021 14:25:28 GMT
Content-Type: text / html; charset = UTF-8
Connection: keep-alive
Server: Apache
X-Powered-By: PHP / 7.3
Set-Cookie: PHPSESSID = a10d873a06024ca42cf32d4ac4ae87ea; path = /; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID = a10d873a06024ca42cf32d4ac4ae87ea; expires = Fri, 27-Aug-2021 14:25:28 GMT; Max-Age = 2592000; path = /; secure; HttpOnly; SameSite = Strict
So it looks like there is a 302 redirect to my 404.php page which does return the 404 code
For SEO, I would like it to return code 404 directly. So I must have done something wrong but I can't seem to find ...
An idea ? Thank you !
I reduced the htaccess file to :
DirectoryIndex index.php
Options +FollowSymlinks
Options -Indexes
ErrorDocument 404 https://www.mapaetmoi.fr/404.php
And the issue is the same.
I wonder if it could not come from the point of the domain name (managed by a provider A) on the hosting (managed by a provider B)? Do you think this could be the case?
I think i have the solution
I replace ErrorDocument 404 https://www.mapaetmoi.fr/404.php
By ErrorDocument 404 /404.php
And it works !

302 redirect loop... with a twist

I have this situation that utterly baffles me:
The setup
a newly setup server (centos 7, apache, mysql, nothing fancy) that hosts a simple php app that I need to interact with from my main app on another server. This service is setup to run on service-name.domain.tld while the main app is on domain.tld (just mentioning in case it make any difference).
The problem
For some reason when I try to access the service app from the main server I get an endless loop of 302 redirects.
If I do a curl -D - http://service-name.domain.tld from the main server I get:
HTTP/1.1 302 Found
Date: Wed, 03 Aug 2016 12:30:26 GMT
Server: Apache
Location: http://service-name.domain.tld
Content-Length: 218
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved here.</p>
</body></html>
If I do the same command from my computer, the result is
HTTP/1.1 200 OK
Date: Wed, 03 Aug 2016 12:31:39 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.6.24
X-Powered-By: PHP/5.6.24
Cache-Control: no-cache
Content-Length: 30
Content-Type: text/html; charset=UTF-8
Welcome.
As it should be. Same happens for any request I make (even static files). Also I should specify same situation happens for wget and get_file_contents in php
I'm really lost right now, not knowing where to go from here. So any kind of direction is greatly appreciated.

url excluded by still returning via varnish

I have excluded the url like this from my varnish cache
if (req.url ~ "^/folder_name/") {
return (pass);
}
but still when i access curl -I http://ip/folder_name i see the below response
HTTP/1.1 301 Moved Permanently
Date: Mon, 04 Jul 2016 08:48:46 GMT
Server: Apache/2.2.15 (CentOS)
Location: http://ip/folder_name/
Content-Length: 319
Content-Type: text/html; charset=iso-8859-1
X-Varnish: 294958
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive
Can anyone please tell me what am i doing wrong, i need to exclude
"all urls that start with /folder_name" from being cached in varnisg
Your regex ends in a slash and "http://ip/folder_name does" not - could this be it?

What is causing this 301 redirect? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
The community reviewed whether to reopen this question 8 months ago and left it closed:
Original close reason(s) were not resolved
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
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 :)
The presence of an X-Powered-By: PHP header means that wordpress is issuing the 301. It's due to wordpress forcing www.mylesgray.com. When you use a nonstandard port, user agents will generally include the port in the Host: header. Try adding
fastcgi_param HTTP_HOST $host;
with the rest of your fastcgi_param directives (or alog with your "include fastcgi_params;") and it should fix this.

Resources