Solved

mod rewrite wildcard subdomain to folders

Posted on 2009-05-04
7
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is socket pooling? 8 73
How to use 2 separate DNS names. 5 50
internal SLA's for IT provision 6 31
is a device online 4 29
#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

738 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