Question

I have a portal site http://www.mysite.com/ where customers sign up and they get their own subdomain version of the site to run my app. I've set up the wildcard subdomain DNS/VirtualHost etc and got it working.

What I am trying to set up is my htaccess file to pass the wildcard subdomain as a parameter to the app, like this:

http://wildcardsubdomain.mysite.com/ -> http://www.mysite.com/app/?dj=wildcardsubdomain
http://wildcardsubdomain.mysite.com/?l=genres -> http://www.mysite.com/app/?dj=wildcardsubdomain&l=genres

I accomplished this by having this in my .htaccess file in http://www.mysite.com/

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://www.mysite.com/app/dj/%1 [P,L]

But I need to redirect the admin user URLs as follows and I've gotten stuck with the htaccess code to use inside the /app directory. What I need is:

http://wildcardsubdomain.mysite.com/admin/?l=genres -> http://www.mysite.com/app/admin.php?dj=wildcardsubdomain&l=genres
http://wildcardsubdomain.mysite.com/admin/?l=users -> http://www.mysite.com/app/admin.php?dj=wildcardsubdomain&l=users

(the l parameter varies, I've just used users and genres here as an example)

I've tried this inside /app/.htaccess but it hasnt really worked:

RewriteRule ^dj/([^/]+)/?$ $2?dj=$1 [QSA,L]
RewriteRule ^admin/([^/]+)/?$ admin.php$2?dj=$1 [QSA,L]

Can anyone suggest a better rewrite rule? Many thanks in advance

Was it helpful?

Solution

You're missing a QSA flag, as the l=genres gets lost otherwise. You just need an "admin" rule before your other rule:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^admin/?$ http://www.mysite.com/app/admin.php?dj=%1 [P,L,QSA]

RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://www.mysite.com/app/dj=%1 [P,L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top