3

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

Lucas Young
  • 187
  • 2
  • 13

1 Answers1

0

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]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Hi, thanks for this. Replaced the main site htaccess with your code which works, but not for the admin links (see my original post.) The app/ directory htaccess: `#app original rules Options -MultiViews Options -Indexes RewriteEngine On RewriteRule ^index.html index.php RewriteRule ^admin admin.php # my rules RewriteRule ^dj/([^/]+)/?$ $2?dj=$1 [QSA,L] RewriteRule ^admin/([^/]+)/?$ admin.php$2?dj=$1 [QSA,L]` Do I need to change my rules in the /app folder htaccess file? – Lucas Young Sep 11 '13 at 02:42