asked in Software by (8.2k points)
0 like 0 dislike
493 views

I simply want to redirect all subdomains that are not already mentioned in a vhost's ServerName to redirect to subdomain. How to redirect all subdomains to main domain inside Apache vhost?

Me need redirect all subdomains to main domain in Apache webserver. How I can to make redirect all subdomains to main domain in Apache software?


apache redirect all subdomains to main domain

1 Answer

0 like 0 dislike
answered by (8.2k points)

Add a block below main block in your vhost configuration file. Specify ServerAlias using wildcard * for subdomains. Finally, specify redirect address using RedirectPermanent.

<VirtualHost *:80>
	DocumentRoot /var/www/html
	ServerName site.loc
	<Directory /var/www/html/>
		Options FollowSymLinks
		AllowOverride All

		# Order Allow,Deny
		# Allow from all

		# Require all granted
	</Directory>
</VirtualHost>

<VirtualHost *:80>
	DocumentRoot /var/www/html
	ServerAlias *.site.loc
	RedirectPermanent / http://site.loc/
</VirtualHost>

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related questions

0 like 0 dislike
1 answer 5 views
0 like 0 dislike
1 answer 20 views
0 like 0 dislike
1 answer 13 views
0 like 0 dislike
1 answer 39 views
0 like 0 dislike
1 answer 40 views
0 like 0 dislike
1 answer 32 views
0 like 0 dislike
1 answer 31 views
...