Welcome to WebmasterWorld Guest from 34.237.76.249

Forum Moderators: Ocean10000 & phranque

301 throwing a 404

     
3:57 pm on Jun 23, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1908
votes: 3


I have a redirect set up after moving a page from one site to it's own domain and it's throwing a 404.

Here is the relevant code:

RewriteRule ^was-folder-name/name-of-article\.html$ http://www.example.com/name-of-article.html [R=301,L]

When I enter the old url for that page I get this results for the original site:
https://www.example.com/missing.html

I checked all urls when I first set this up and they were working. I think this started after setting up the original site with HTTPS.

Can anyone see what's wrong?
8:32 pm on June 23, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11768
votes: 223


You should try using an HTTP response checker which will show you the response status chain and all the response headers.
You should specifically examine the status codes and the Location: headers that are returned.

btw I'm guessing your redirect target should be https:
9:22 pm on June 23, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 29, 2005
posts:10103
votes: 1002


Palm. Meet forehead. Smack!

Good catch!
2:40 am on June 24, 2019 (gmt 0)

New User from US 

Top Contributors Of The Month

joined:June 21, 2019
posts: 29
votes: 2


Let's assume this is your url you want to redirect >>> https://myolddomain.com/some-folder/some-page.html

Here is a one line solution, put this as your first redirect before any redirect rules you may already have. These one liners execute first.


Redirect 301 /some-folder/some-page.html https://www.mynewdomain.com/my-new-page.html


( you could specify the whole url if you wanted to )


[edited by: not2easy at 3:20 am (utc) on Jun 24, 2019]
[edit reason] readability [/edit]

8:53 am on June 24, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11768
votes: 223


Here is a one line solution, put this as your first redirect before any redirect rules you may already have. These one liners execute first.


assuming there is or eventually will be a hostname canonicalization redirect (which will necessarily use mod_rewrite), you are potentially creating an unnecessary chained redirect as follows:
- when http://example.com/some-folder/some-page.html is requested, the mod_rewrite directives will fire first (see reference below), and the hostname canonicalization ruleset will redirect the request to https://www.example.com/some-folder/some-page.html
- when https://www.example.com/some-folder/some-page.html is subsequently requested it will fire the mod_alias rule and provide a second redirect to https://www.example.com/my-new-page.html

this ultimate request can be achieved with the first redirect if you do everything using mod_rewrite and put this before the generic hostname canonicalization redirect:
RewriteRule ^some-folder/some-page\.html$ https://www.mynewdomain.com/my-new-page.html [R=301,L]


reference:
https://httpd.apache.org/docs/current/rewrite/avoid.html#redirect
The use of RewriteRule to perform this task may be appropriate if there are other RewriteRule directives in the same scope. This is because, when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file.
3:21 pm on June 25, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1908
votes: 3


@phranque

I ran the url through the redirectcheck.com http checker.

The location where the page was moved (from a folder on one site, to it's own domain) was correct, however, it is still throwing a 404 on the original domain any time anyone tries to access one of those pages on the old site.

The new domain is not set up for https yet. It's a non-profit hobby site.

Here are the results of the https checker:

HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Jun 2019 14:50:32 GMT
Server: Apache
Location: http://www.example.com/some-page.html
Cache-Control: max-age=2592000
Expires: Thu, 25 Jul 2019 14:50:32 GMT
Content-Length: 259
Content-Type: text/html; charset=iso-8859-1

http://www.example.com/some-page.html (this is the correct url)

HTTP/1.1 404 Not Found
Date: Tue, 25 Jun 2019 14:50:33 GMT
Server: Apache
Accept-Ranges: bytes
Transfer-Encoding: chunked
Content-Type: text/html

------

BTW, I had originally set up a redirect for the whole site, but then found that the pages weren't getting redirected so entered them all individually.

Here is the redirect for moving the whole site:
RewriteRule ^some-page/$ http://www.example.com/ [R=301,L]

This goes to the proper page on the new site but only for the home page.

I have this redirect at the beginning of the 301's. Should I move it to the end?
4:36 pm on June 25, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15752
votes: 825


This goes to the proper page on the new site but only for the home page.

I really hate this damned machine
I wish that they would sell it
It never does quite what I want
But only what I tell it.
4:55 pm on June 25, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:Nov 13, 2016
posts:1167
votes: 273


It never does quite what I want
But only what I tell it.

Hopefully smart objects are coming to the rescue :)
5:06 pm on June 25, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1908
votes: 3


@lucy24 and @Dimitri

Perhaps you didn't read my response. The URL that I started this thread about is still throwing a 404.

It's the 301 for the home page that is working (and only that one). the 301s' for all the inner pages are throwing a 404.
5:14 pm on June 25, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:Nov 13, 2016
posts:1167
votes: 273


RewriteRule ^some-page/$ http://www.example.com/ [R=301,L]

I am no longer using Apache since 10+ years, so I don't really remember, but in your example, shouldn't you mention the destination "folder/page" ? Because you put only the destination domain name, or may be this is what the "L" is doing ?
6:59 pm on June 25, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4391
votes: 310


Here is the redirect for moving the whole site:
RewriteRule ^some-page/$ http://www.example.com/ [R=301,L]
That rule sends every request for an URL containing "some-page/" to the root URL of the other domain so you can see why only one page would be the one you intended to land there. To send each page to it's own replacement (new) page you need to capture the requested page and add that on to the request again. Your rule is not capturing the entire request, it is simply rewriting all requests containing "some-page/" to the new domain's root.

http://www.example.com/some-page.html (this is the correct url)
Is there an actual "some-page.html" on the new domain - or is that old "some-page.html" now the index.html page in the root of the new domain? The header checker results say that page is not found on the new domain.

7:07 pm on June 25, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15752
votes: 825


Oh yes and...
Redirect 301
KnowOne, you have stumbled into a long-running quarrel in the Apache subforum. Short version:

Premise: On 99 out of 100 servers, mod_rewrite executes before mod_alias. On shared hosting, this is out of your power to change.
Premise: Some types of redirect, such as canonicalization, can only be done in mod_rewrite.
Coclusion (this is where the quarrels start): It is safer to do all your redirects in mod_rewrite.
2:42 pm on June 27, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1908
votes: 3


#not2easy

I originally had all the old pages in a folder and used .html as the home page for this folder so yes, there is an html file for the home page on both old folder and new website.

Here is the redirect I was using for moving all old files to their own domain:

RewriteRule ^some-page/$ http://www.example.com/ [R=301,L]

This works for the home page whether I include the .html for the home page or not.

However, if I want it to move **all** the old pages to the new domain I need to leave it off.

It is not moving all the other pages, however, and that is why I set up the individual redirects for each page. This is slowing down the original site however as there are 70 pages on this site.

Can someone let me know what I need to include in that one redirect so it will move all old pages from the old folder to it's new domain (then I can remove all the individual redirects)
3:30 pm on June 27, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4391
votes: 310


Is this a wordpress site by any chance?
3:48 pm on June 27, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1908
votes: 3


@not2easy

No it's a hand written static site.
5:03 pm on June 27, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4391
votes: 310


Your rule:
RewriteRule ^some-page/$ http://www.example.com/ [R=301,L] 
would need to capture the name of the page in order for it to send visitors to that page rather than the root, but it depends on what else you have in the htaccess file.

Ordinarily
RewriteRule ^some-page/?$ http://www.example.com/$1 [R=301,L] 
would capture the page requested and add it to the end.

If you are seeing
... a 404 on the original domain any time anyone tries to access one of those pages on the old site.
it is because of 2 things: the old page is not there any more and because the request is coming before the rewrite rule. If the request was hitting the rewrite rule before hitting the canonical rewrite, it would never see that the old page is not there any more.

You mentioned that it "was working" before you changed the old domain to https, so it sounds like you put that https rewrite before this rule (though that is not what the header checker showed). I am guessing that the order of rules may be causing the error and/or they do not all use mod_rewrite - but I can only guess. If a rewrite rule on the old domain sends the request to the new domain it should not also be requesting the same page on the old domain.

5:13 pm on June 27, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15752
votes: 825


would capture the page requested and add it to the end.
But there's no (capture) (in parentheses) in the quoted rule.