Page 1 of 1

.htaccess rewrite subdomain with wildcard for any subdomain

Posted: Thu Apr 08, 2021 2:09 pm
by steve102
I have many multiple subdomains and would like an example how my .htaccess would look like using a wild card so I can rewrite any http://*.example.com to either goto the root or goto a folder.

This is what I have tried but it does not seem to work. I have activated Rewrites in apache2.

Code: Select all

Options +Includes +ExecCGI +FollowSymLinks

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^((?!subdomain/).*)$ example.com $1 [L,NC]

AddType application/x-httpd-cgi .cgi .pl
AddType text/html .htm
AddHandler server-parsed .shtml .sht .html .htm

The above coding is the closest I think I could find . I am new to mod rewrites and their syntax meanings.

I have all my subdomains in my apache2 /etc/apache2/sites-enabled/httpd-vhosts-user.conf.

During my research I have tried many variants but cannot seem to get the syntax.

Like I mentioned, I have many multiple subdomains and have researched on line but with no luck.

**System set up:** I am using ubuntu server 18.04.5, running on a Qnap TS-453D,64-bit x86, IntelĀ® CeleronĀ® J4125 quad-core 2.0 GHz processor, 8GB Mem. Using VirtualizationStation 3 VMs, 6TB Disk Space Raid 5.

Re: .htaccess rewrite subdomain with wildcard for any subdomain

Posted: Thu Apr 08, 2021 2:17 pm
by steve102
The above coding is the closest I think I could find . I am new to mod rewrites and their syntax meanings. .htaccess seems like such a powerful tool. I would like an example of what the code should look like for my needs So, I can better research their meanings and uses.
Thank you!