Expand my Community achievements bar.

SOLVED

Redirect the url https://tooB.com.br and https://tooBB.com to https://tooA.com (vhost and dispatcher ?)

Avatar

Level 2
I have 3 url's with the same content, that is, the 3 sites have the same content, but I would like any user to access the url's https://tooB.com.br or https://tooBB. com were redirected to the URL https://tooA.com in your browser, simple as that.
I was told to change my dispatcher -> src -> conf.d -> available_vhosts
In this path I have two files, default.vhost and too.vhosts, both with almost the same content, the difference is that default.vhost is as follows:

# Include customer defined variables
Include conf.d/variables/custom.vars
 
<VirtualHost *:80>
ServerName "publish"
# Put names of which domains are used for your published site/content here
ServerAlias "*"
# Use a document root that matches the one in conf.dispatcher.d/default.farm
DocumentRoot "${DOCROOT}"
# URI dereferencing algorithm is applied at Sling's level, do not decode parameters here
AllowEncodedSlashes NoDecode
# Add header breadcrumbs for help in troubleshooting
<IfModule mod_headers.c>
Header add X-Vhost "publish"
</IfModule>
 
 
 
and too.vhost looks like this:
 
# Include customer defined variables
Include conf.d/variables/custom.vars
 
<VirtualHost *:80>
ServerName https://tooA.com
# Put names of which domains are used for your published site/content here
# Use a document root that matches the one in conf.dispatcher.d/default.farm
DocumentRoot "${DOCROOT}"
# URI dereferencing algorithm is applied at Sling's level, do not decode parameters here
AllowEncodedSlashes NoDecode
# Add header breadcrumbs for help in troubleshooting
<IfModule mod_headers.c>
Header add X-Vhost "publish"
</IfModule>
 
 
 

But even if the user enters the 3 URLs in the browser search, the entered URL always returns, that is, if he accesses by typing https://tooBB.com, https://tooBB.com will appear in the url field,
If he types in the search https://tooB.com.br https://tooB.com.br will appear.

 

What I mean is that when the user types in the search https://tooB.com.br or https://tooBB.com, the url is automatically changed to https://tooA.com

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi @EvertonSa2,

that is expected, as both domains are added as aliases in your VHOST. Therefore, they are supported, not redirected. You should be able to achieve what you need with an Apache rewrite rule, something like:

 

# Redirect from tooB.com.br
RewriteCond %{HTTP_HOST} ^(www\.)?tooB\.com\.br$ [NC]
RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]

# Redirect from tooBB.com
RewriteCond %{HTTP_HOST} ^(www\.)?tooBB\.com$ [NC]
RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]

 

These are examples of 301 redirect rules that can be added to your too.vhost file.

 

Hope this helps,

Daniel

View solution in original post

8 Replies

Avatar

Correct answer by
Level 9

Hi @EvertonSa2,

that is expected, as both domains are added as aliases in your VHOST. Therefore, they are supported, not redirected. You should be able to achieve what you need with an Apache rewrite rule, something like:

 

# Redirect from tooB.com.br
RewriteCond %{HTTP_HOST} ^(www\.)?tooB\.com\.br$ [NC]
RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]

# Redirect from tooBB.com
RewriteCond %{HTTP_HOST} ^(www\.)?tooBB\.com$ [NC]
RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]

 

These are examples of 301 redirect rules that can be added to your too.vhost file.

 

Hope this helps,

Daniel

Avatar

Level 2

Hello @daniel-strmecki 

So is this how I have to change my too.vhost ?

 

<VirtualHost *:80>
	ServerName	https://tooA.com
	# Put names of which domains are used for your published site/content here
	ServerAlias	  https://tooB.com.br https://tooBB.com
	# Use a document root that matches the one in conf.dispatcher.d/default.farm
	DocumentRoot "${DOCROOT}"
	# URI dereferencing algorithm is applied at Sling's level, do not decode parameters here
	AllowEncodedSlashes NoDecode
	# Add header breadcrumbs for help in troubleshooting
	<IfModule mod_headers.c>
		Header add X-Vhost "publish"
	</IfModule>
	<Directory />
		<IfModule disp_apache2.c>
			# Some items cache with the wrong mime type
			# Use this option to use the name to auto-detect mime types when cached improperly
			ModMimeUsePathInfo On
			# Use this option to avoid cache poisioning
			# Sling will return /content/image.jpg as well as /content/image.jpg/ but apache can't search /content/image.jpg/ as a file
			# Apache will treat that like a directory.  This assures the last slash is never stored in cache
			DirectorySlash Off
			# Enable the dispatcher file handler for apache to fetch files from AEM
			SetHandler dispatcher-handler
                        # Redirect from tooB.com.br
                        RewriteCond %{HTTP_HOST} ^(www\.)?tooB\.com\.br$ [NC]
                        RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]

                        # Redirect from tooBB.com
                        RewriteCond %{HTTP_HOST} ^(www\.)?tooBB\.com$ [NC]
                        RewriteRule ^(.*)$ https://tooA.com/$1 [L,R=301]
		</IfModule>

 

Avatar

Level 6

Hi @EvertonSa2 
I believe what @daniel-strmecki explained should work and that you got it right in your example.

The only small question mrk I have in my mind is a about the need to have the [NC] or not at the end. That is for case-insensitive matching, but domains by default do not care about case sensitivity, so ..... not sure if really needed. But maybe I am wrong.....

For more Apache flags you can check docs: https://httpd.apache.org/docs/2.4/rewrite/flags.html

Avatar

Level 9

Hi @EvertonSa2,

please check the Apache documentation. I believe you are missing some config to enable rewrites first. Here is an example rewrite rule from my project:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower
# Include general rewrite rules
# Include conf.d/rewrites/rewrite.rules

# Remove trailing slash
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)/+$ https://%{HTTP_HOST}$1 [R=301,L]
</IfModule>

 

Good luck,

Daniel

Avatar

Community Advisor

Hi @EvertonSa2 
Are you using CDN, if yes then you can put redirects there and completely remove dispatcher config for 3rd domain.



Arun Patidar

Avatar

Level 2
Hi @arunpatidar 
Do you have any documentation explaining how to perform this redirection via the CDN?

 

Avatar

Level 9

Hi @EvertonSa2,

it is documented here: https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

 

You can do redirects both on CDN and Apache, usually closer to the client is better - CDN.

 

Good luck,

Daniel

Avatar

Level 2

Hi @daniel-strmecki 

Thanks for the help, I´ll take a look if it´s easier via the CDN.