mcdsoftware Posted September 26, 2010 Share Posted September 26, 2010 Hey guys, I've been trying out different things for several days now and have finally decided to ask for help. So here's the situation, we have a site (domain.com) and wildcard dns is setup and working properly. entering someone.domain.com displays domain.com's content so all is good there. What I need is to process a different script (note: not redirect, the url must be masked), like if the request is dummy.domain.com, it should mask the url to stay the same but really process /public_html/partners/dummy. It works as intended until I try to visit a directory like dummy.domain.com/files where it redirects the browser to domain.com/partners/dummy/files Here's what I have on public_html/.htaccess RewriteEngine On Options +FollowSymLinks RewriteBase / RewriteCond %{HTTP_HOST} !www.domain.com$ [NC] RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC] RewriteRule (.*) http://domain.com/partners/%1/$1 [P,L] If I try to visit a non-existent directory like dummy.domain.com/asdf, it works fine. The 404 says that it cant find the directory or file at partners/dummy/asdf so I'm thinking it must be something on the /files directory. Here's the htaccess under the files directory <IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymLinks RewriteBase files/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [L] </IfModule> Hope you guys can help me out. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/214410-wildcard-subdomain-and-masking-with-htaccess/ Share on other sites More sharing options...
cags Posted September 26, 2010 Share Posted September 26, 2010 What happens if you remove 'http://domain.com/' from the start of the substitution, leaving you with... RewriteEngine On Options +FollowSymLinks RewriteBase / RewriteCond %{HTTP_HOST} !www.domain.com$ [NC] RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC] RewriteRule (.*) partners/%1/$1 [P,L] Quote Link to comment https://forums.phpfreaks.com/topic/214410-wildcard-subdomain-and-masking-with-htaccess/#findComment-1115812 Share on other sites More sharing options...
mcdsoftware Posted September 26, 2010 Author Share Posted September 26, 2010 Thanks cags. I tried that but it just goes into an infinite loop. I think that's because the condition that checks for the wildcard subdomain is always true and it redirects it everytime to /partners/xxx/xxx. Is there any flag that I could use to stop the loop after the first request/redirect? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/214410-wildcard-subdomain-and-masking-with-htaccess/#findComment-1115820 Share on other sites More sharing options...
cags Posted September 26, 2010 Share Posted September 26, 2010 It's because the redirected url also matches the pattern (since .* matches everything). You should be able to do something like this to avoid that... RewriteCond %{HTTP_HOST} !www.domain.com$ [NC] RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC] RewriteCond %{REQUEST_URI} !^partners/ [NC] RewriteRule (.*) partners/%1/$1 [P,L] Should only rewrite patterns that done begin with the partners/ directory Quote Link to comment https://forums.phpfreaks.com/topic/214410-wildcard-subdomain-and-masking-with-htaccess/#findComment-1116052 Share on other sites More sharing options...
mcdsoftware Posted September 27, 2010 Author Share Posted September 27, 2010 Thanks so much cags! That worked beautifully Quote Link to comment https://forums.phpfreaks.com/topic/214410-wildcard-subdomain-and-masking-with-htaccess/#findComment-1116151 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.