Solved

mod rewrite wildcard subdomain to folders

Posted on 2009-05-04
7
420 Views
Last Modified: 2013-11-30
I'm trying to do a mod rewrite that will globally rewrite all subdomains to subdirectories unless it is www or example. The below code doesn't seem to work for some reason.
RewriteEngine On
 
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+).vsssl.com$
 
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www|example)$
 
#Check if the directory actually exists before we go there
RewriteCond /home/vsssl/public_html/%1 -d
 
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/vsssl/public_html/
 
#Finally, this is the actual rewrite
RewriteRule (.*) /home/vsssl/public_html/%1/$1 [Last]

Open in new window

0
Comment
Question by:MeridianManagement
  • 3
  • 2
  • 2
7 Comments
 
LVL 42

Expert Comment

by:David S.
ID: 24301669
Try this:
RewriteEngine On
 
#Make sure the subdomain is not www or example
RewriteCond %{HTTP_HOST} !^(www|example)\.vsssl\.com$
 
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+)\.vsssl\.com$
 
#Check if the directory actually exists before we go there
RewriteCond /home/vsssl/public_html/%1 -d
 
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/vsssl/public_html/
 
#Finally, this is the actual rewrite
RewriteRule (.*) /home/vsssl/public_html/%1/$1 [Last]

Open in new window

0
 
LVL 2

Author Comment

by:MeridianManagement
ID: 24301701
no, it didn't work. In fact members.vsssl.com just goes to document root.
0
 
LVL 42

Expert Comment

by:David S.
ID: 24301763
Are you using httpd.conf or .htaccess?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:MeridianManagement
ID: 24301808
.htaccess
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 24310367
"#This stops it from looping"

this stops your rewrite.
RewriteEngine On
 
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+)\.vsssl\.com$
 
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www|example)$
 
#Check if the directory actually exists before we go there
RewriteCond /home/vsssl/public_html/%1 -d
 
RewriteCond %1<>%{REQUEST_FILENAME} !^[^<]+<>/home/vsssl/public_html/\1/
 
RewriteRule ^(.*) /%1/$1 [Last]

Open in new window

0
 
LVL 2

Author Comment

by:MeridianManagement
ID: 24310777
The .htaccess gave me a internal configuration error. Here's one I created for one subdomain, I don't know if that helps. Maybe you could modify this one since it's working?

RewriteEngine On
RewriteCond %{HTTP_HOST}   ^[www\.]*members.vsssl.com [NC]
RewriteCond %{REQUEST_URI} !^/members/.*
RewriteRule   ^(.*)  /members/$1  [L]
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 24313073
The capturing group was missing,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.vsssl\.com$
RewriteCond %{1} !^(www|example)$
RewriteCond /home/vsssl/public_html/%1 -d
RewriteCond %1<>%{REQUEST_FILENAME} !^([^<]+)<>/home/vsssl/public_html/\1
RewriteRule ^(.*) /%1/$1 [Last]

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.htaccess css/images no longer loading 4 41
Internet options/Settings 1 48
Connectivity issues after power outage 5 36
what is mstp 6 38
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question