Jump to content

Recommended Posts

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!

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]

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.