Home > Enterprise >  How to redirect roodomain/addondomain urls to addondomain
How to redirect roodomain/addondomain urls to addondomain

Time:10-05

My host does not know how to fix this. I saw in google results URLs that worry me. For example, I saw rootdomain/addondomain.com/url1.html etc this happened because google bot was not redirected to addondomain.com/url1.html for example

So I want to redirect all URLs to addondomain.com only

Because this created duplicate content. My root domain has nothing to do with addon domain...they have a completely different topic....

I already have redirection from addondomain.rootdomain.com to addon domain in htaccess.... but I want to add the new one too...

This is the code I already have

RewriteCond %{HTTP_HOST} ^addon\.root\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.addon\.root\.org$
RewriteRule ^(.*)$ "https\:\/\/www\.addon\.com\/$1" [R=301,L]

here is the example with some random domains...

root domain is : bonesroot.com
addon domain is : beeraddon.com

and beerroot.com files are in the folder bones.com/beer on the server

so I want to create immediate redirection from bonesroot.com/beer to beeraddon.com is that possible or will it affect the server?

this video explains what I want to do https://www.youtube.com/watch?v=cRm6deeeTVY

and here is the code they recommend

RewriteEngine On
                RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
                RewriteCond %{REQUEST_URI} ^/addonfolder/(.*)$
                RewriteRule ^(.*)$ - [L,R=404]

CodePudding user response:

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addonfolder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]

This is the right idea, but it only triggers a 404. To redirect from https://root.example/addon.example/foo to https://addon.example/foo you would need to do it like this:

# Redirect requests to the subdirectory the addon domain points to
RewriteCond %{HTTP_HOST} ^(www.)?root\.example$ [NC]
RewriteRule ^(addon\.example)(?:$|/(.*)) https://$1/$2 [R=301,L]

This assumes that the subdirectory /addon.example is the same as the name of the addon domain, as described initially in your question. (However, for some reason, you have changed this convention later in your question?! *1)

The $1 backreference contains the subdirectory name (the same as the name of the addon domain). The $2 backreference contains the URL-path less the initial slash prefix.

The RewriteCond directive that you previously had that checked against the REQUEST_URI server variable is not required as this check is better performed in the RewriteRule directive itself.

Test first with a 302 (temporary) redirect to avoid caching issues.


*1 If the name of the subdirectory is different to the name of the addon domain then you will need to hardcode this instead. For example:

# Redirect requests to the subdirectory the addon domain points to
RewriteCond %{HTTP_HOST} ^(www.)?root\.example$ [NC]
RewriteRule ^addon-directory(?:$|/(.*)) https://addon.example/$1 [R=301,L]

TIP: Addon domains (cPanel?) don't need to point to subdomains that point to subdirectories off the main domain. They can point anywhere... including areas outside of the main domains document root. This would avoid having to implement these redirects to begin with.

CodePudding user response:

OK I will explain again. I will use fake domains in this case but very similar to my actual domains

The root domain is alter.org

addon domain is numero.com

numero.com files reside inside alter.org/numero/ folder

I want to keep my current redirects which are also

numero.alter.org/foo which redirects to numero.com

what I have in htaccess is this

RewriteCond %{HTTP_HOST} ^numero\.alter\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.numero\.alter\.org$
RewriteRule ^(.*)$ "https\:\/\/www\.numero\.com\/$1" [R=301,L]

and I want to add also redirect which redirects

alter.org/numero/foo to numero.com/foo

because I saw one google search result like that and it is duplicate content...Immediately when google bot hits the alter.org/numero/foo it needs to be redirected to numero.com/foo

Please tell me how to add a new redirect to the existing one

  • Related