Forum Moderators: phranque

Message Too Old, No Replies

Redirecting pages from expired domain

         

jediviper

10:19 am on Jan 7, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



Hello,
I have a question regarding a problem that I have with a redirect from different pages coming from an expired domain. I need them all to redirect to a single page on another website. Currently it works, but some redirect checker page show that there are 19 redirects in place! I just use some simple commands at the htaccess file of the expired domain though.

So to give an example:
/expiredpage1/
/expiredpage2/
/expiredpage3/
expireddomain.co.uk

I need from these 3 pages and also the domain itself to redirect to www.example.com/newpage/

I have tried these commands:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} expiredomain.co.uk [NC]
RewriteRule ^(.*)$ https://www.example.com/newpage/ [R=301,NC]

Or these commands:
Redirect 301 /expiredpage1/ https://www.example.com/newpage/
Redirect 301 /expiredpage2/ https://www.example.com/newpage/
Redirect 301 /expiredpage3/ https://www.example.com/newpage/
Redirect 301 / https://www.example.com/newpage/


[edited by: not2easy at 5:36 pm (utc) on Jan 7, 2021]
[edit reason] 'example.com' for readability [/edit]

lucy24

4:51 pm on Jan 7, 2021 (gmt 0)

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



mod_alias (Redirect by that name) can't look at the hostname. So if that's a necessary part of the rule, you'll need to stick with mod_rewrite. If, on the other hand, the old pages happen to have names that aren't used by any current site on the same server, you don't need to check the hostname at all. (But you should almost certainly be using mod_rewrite anyway.)

19 redirects? You mean 19 different redirects for 19 different starting URLs, or a chain of 19 redirects? I'm not sure modern browsers will even permit that long a chain.

Incidentally ... by “expired” do you simply mean inactive? Once a domain is genuinely expired, there will no longer be a DNS, and requests won't reach your server.

phranque

12:30 am on Jan 8, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I need from these 3 pages and also the domain itself to redirect to www.example.com/newpage/

I have tried these commands:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} expiredomain.co.uk [NC]
RewriteRule ^(.*)$ https://www.example.com/newpage/ [R=301,NC]

Or these commands:
Redirect 301 /expiredpage1/ https://www.example.com/newpage/
Redirect 301 /expiredpage2/ https://www.example.com/newpage/
Redirect 301 /expiredpage3/ https://www.example.com/newpage/
Redirect 301 / https://www.example.com/newpage/

if you are using mod_rewrite anywhere (such as anything that requires examining the hostname) you should avoid mod_alias (Redirect[Match]) everywhere.
see this for why:
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.

i would define a pattern that matches all the paths that need to be redirected in one RewriteRule directive.

something like this:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?expiredomain\.co\.uk$ [NC]
RewriteRule ^(expiredpage1/|expiredpage2/|expiredpage3/)?$ https://www.example.com/newpage/ [R=301,L]

jediviper

8:01 am on Jan 11, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



@lucy24
yeap, a redirect chain of 19 redirects according to [redirect-checker.org...]
I do hope that this tool is correct though.
And yes, it's an expired domain, as inactive, so what do u mean that the requests won't reach my server. Since there are active links towards that expired domain, which are redirected to one of my sites.

@phranque
thanks a lot for your suggestions. If I got it right, u mean that I should avoid using both the Rewrite code and the redirect commands.

For now, I have removed the Rewrite code and left only the 4 redirects commands and they all seems to redirect correctly according to the above tool.

phranque

8:29 am on Jan 11, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



And yes, it's an expired domain, as inactive, so what do u mean that the requests won't reach my server. Since there are active links towards that expired domain, which are redirected to one of my sites.

if your domain registration has lapsed, then there is no way to specify a domain name server, which means there's no way to send that domain's traffic to a web server.

I have removed the Rewrite code and left only the 4 redirects commands and they all seems to redirect correctly according to the above tool.

do these Rewrite directives exist on the example.com virtual hostname or the expiredomain.co.uk virtual hostname?
if the answer is example.com, what happens when you request https://example.com/ ?
if the answer is expiredomain.co.uk, how does your expired domain resolve to your web server's IP address?

lucy24

5:36 pm on Jan 11, 2021 (gmt 0)

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



yeap, a redirect chain of 19 redirects
You can check this yourself in at least two ways. First, since they are redirects you will see them in logs as nineteen consecutive requests before finally arriving at a 200 response. Second, any browser utility such as LiveHeaders (I think it's got a different name now) will show everything that happens to a request.

jediviper

9:53 am on Jan 13, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



@phranque

All these redirect commands are included in the htaccess file of the expired domain host.
I don't get the part of your question about how does the domain resolve to the IP.

phranque

10:46 am on Jan 13, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I don't get the part of your question about how does the domain resolve to the IP.

if your domain registration has lapsed, then there is no way to specify a domain name server, which means there's no way to send that domain's traffic to a web server.


All these redirect commands are included in the htaccess file of the expired domain host.

- either your domain is expired and therefore there's no way to specify a way to find this web host
- or you have a web host for your domain which means it hasn't expired yet

lucy24

5:55 pm on Jan 13, 2021 (gmt 0)

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



I think it’s possible you’re using the word “expired” when actually you just mean “inactive”. Some clarification might help everyone.

jediviper

2:36 pm on Jan 14, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



Hmm, when u buy an expired domain and then you just host it somewhere (just to get access to the htaccess file) is what you call as inactive?

lucy24

5:49 pm on Jan 14, 2021 (gmt 0)

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



Oh. You don’t mean expired at all, except in the sense that it was previously used by someone else for some other purpose. If you “buy” a domain, it is now registered to you--at least for the next year. All this time, I thought the thread was about domains that you formerly used, and have now discontinued.

Query: Why are you interested in requests for someone else’s domain, with presumably entirely different content and a different target audience from your own sites? The bare fact that it was allowed to expire suggests that it didn’t hold much value to the previous registrant.

jediviper

8:28 am on Jan 15, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



Because of the value of the links.
And no, it's not entirely different content. It's exactly on the same business, so 100% relevant.

So I fixed the problem with the redirects of one expired domain and now I have 0 redirects from another one. I followed your tips here and I get no redirects at all.. Really troubled about this one.
I use the free infinityfree.net host service and no matter what commands I use, I get nothing. I even tried the default redirect service through the Cpanel and I get no redirects.
My request is to:
- the main domain to be 301 to https://www.example.com/newpage/
- all or specific pages of the expired domain (for example expired.co.uk/folder/page.html) to be 301 to https://www.example.com/newpage/
- all above to work for www and non www pages

In my htaccess I have currently this:

redirectMatch 301 ^(.*)$ https://www.example.com/newpage/
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?expireddomain\.co\.uk$ [NC]
RewriteRule ^(folder/page.html)/|expiredpage2/|expiredpage3/)?$ https://www.example.com/newpage/ [R=301,L]

phranque

9:01 am on Jan 15, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



redirectMatch ...
...
RewriteRule ...

remember where i said this?
if you are using mod_rewrite anywhere ... you should avoid mod_alias (Redirect[Match]) everywhere.

In my htaccess I have currently this

this should work without the RedirectMatch directive.
So I fixed the problem with the redirects of one expired domain and now I have 0 redirects from another one.

did you change the hostname pattern in the RewriteCond directive to match the other expired domain?

jediviper

7:47 am on Jan 18, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



"if you are using mod_rewrite anywhere ... you should avoid mod_alias (Redirect[Match]) everywhere."

You are right, you have mentioned that before. The redirectmatch command was added automatically from the Cpanel, when I added there a redirect.

Will keep everything in mind, thank you again for the advices.

phranque

1:05 am on Jan 19, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The redirectmatch command was added automatically from the Cpanel, when I added there a redirect.

i would remove any CPanel redirects and stop using that feature.
you should manage any additional required redirects in .htaccess using mod_rewrite directives.

phranque

1:05 am on Jan 19, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



now I have 0 redirects from another one.

is this problem now solved?

jediviper

9:24 am on Jan 19, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



Well yes, it seems that the redirects work normally.
For some reason in Ahrefs they look broken though.

not2easy

12:05 pm on Jan 19, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The main reason that people suggest not to use CPanel for redirects is because it defaults to a 302, not a 301. Always check your logs to see server response codes and do not use CPanel shortcuts. They are incompatible with hard coded rewrites.

Robert Charlton

9:27 am on Feb 21, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Here's another post on potential CPanel problems, a bit more detailed, from jdMorgan back in May 2006, which I've kept bookmarked.

This answer, in the thread below, is tailored specifically for a www- or non-www domain redirect issue... but the description of problems CPanel creates (and which mod_rewrite resolves) is particular clear...

Multiple Redirects For Same Page
Found pages that were being redirected 2 times
May 2006
https://www.webmasterworld.com/forum92/6283.htm [webmasterworld.com]

The basic problem is that by using cpanel to 'write' the code, you cannot control the order in which the redirect directives are added, or what order they execute in.

If you use mod_rewrite for the per-page redirects in .htaccess, and place them above the domain redirect, then your problem will disappear. To emphasize: You must use mod_rewrite for all redirects; If you mix mod_alias and mod_rewrite directives, then --in a normal server configuration-- the mod_alias directives will all execute first. Because mod_rewrite is *required* if you want to do conditional rewrites/redirects, this establishes the need to use mod_rewrite for all redirects.

Once you've done this, if an incorrect page URL is requested from either www- or non-www domain, it will be redirected to the correct page, but always in the 'correct' www domain. But, if the requested URL does not match a page that is to be redirected, the code will fall through to the domain redirect at the end, where the domain redirect will be invoked if the page is correct, but the domain is incorrect....

jediviper

3:02 pm on Feb 22, 2021 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks for the update.

System

3:08 pm on Mar 3, 2021 (gmt 0)

redhat



The following 2 messages were cut out to new thread by phranque. New thread at: google/5029177.htm [webmasterworld.com]
10:17 pm on Mar 5, 2021 (utc -8)

[edited by: phranque at 5:38 am (utc) on Mar 7, 2021]
[edit reason] fix link [/edit]