.htaccess rewrite subdomain with wildcard for any subdomain

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.
Post Reply
User avatar
steve102
Know my way around
Posts: 151
Joined: Sat Dec 20, 2014 2:53 am
Location: Maine
Contact:

.htaccess rewrite subdomain with wildcard for any subdomain

Post by steve102 » Thu Apr 08, 2021 2:09 pm

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.
Nas1: TS-453D -Firmware: 4.5.3 Build 1652
Nas2: TS-453D -Firmware: 4.5.3 Build 1652
Nas3: TS-253 Pro-Firmware: 4.5.3 Build 1652
Nas4: TS-451+ -Firmware: 4.5.3 Build 1652
Windows 7 | Apple| Linux | Apache | Perl

User avatar
steve102
Know my way around
Posts: 151
Joined: Sat Dec 20, 2014 2:53 am
Location: Maine
Contact:

Re: .htaccess rewrite subdomain with wildcard for any subdomain

Post by steve102 » Thu Apr 08, 2021 2:17 pm

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!
Nas1: TS-453D -Firmware: 4.5.3 Build 1652
Nas2: TS-453D -Firmware: 4.5.3 Build 1652
Nas3: TS-253 Pro-Firmware: 4.5.3 Build 1652
Nas4: TS-451+ -Firmware: 4.5.3 Build 1652
Windows 7 | Apple| Linux | Apache | Perl

Post Reply

Return to “Web Server & Applications (Apache + PHP + MySQL / SQLite)”