Forum Moderators: phranque
[edited by: not2easy at 5:36 pm (utc) on Jan 7, 2021]
[edit reason] 'example.com' for readability [/edit]
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/
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.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?expiredomain\.co\.uk$ [NC]
RewriteRule ^(expiredpage1/|expiredpage2/|expiredpage3/)?$ https://www.example.com/newpage/ [R=301,L]
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.
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.
yeap, a redirect chain of 19 redirectsYou 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.
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.
redirectMatch ...
...
RewriteRule ...
if you are using mod_rewrite anywhere ... you should avoid mod_alias (Redirect[Match]) everywhere.
In my htaccess I have currently this
So I fixed the problem with the redirects of one expired domain and now I have 0 redirects from another one.
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....
[edited by: phranque at 5:38 am (utc) on Mar 7, 2021]
[edit reason] fix link [/edit]