0

I am close to achieving my goal but I cannot come up with the correct solution to my problem.

I have written the following rules for my wildcard subdomains:

#remove www.
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain\.com/$1 [R=301,L]

#rewrite subdomains to /club/<clubname as defined by subdomain>/<whatever was here before>
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/club/%1/$0 [NC,L]

This is desperately close to what I require, ie if I go to http://alpha.domain.com/some/string/here the URL is rewritten to http://domain.com/club/alpha/some/string/here

however

I would like the url in browser to still look like the original url

Many thanks in advance

EDIT: I have tried just adding PT to the final rule but that doesn't work, I get a 400 error

EDIT2: For anyone interested, I abandoned this line of enquiry and instead used php to read the text in the subdomain.

amcc
  • 2,608
  • 1
  • 20
  • 28

1 Answers1

1

If the www.example.com subdomain uses the same virtual host as the example.com domain, you can just use an internal rewrite by using a relative path:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond $0 !^club/
RewriteRule ^(.*)$ club/%1/$0 [NC,L]

Otherwise you will need a proxy:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/club/%1/$0 [NC,L,P]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Thanks but I get an error 500 on the first and a 404 on the second – amcc Feb 10 '11 at 17:30
  • @Vanthel: Where do you use that rule? In the .htaccess file in the document root directory? – Gumbo Feb 10 '11 at 17:33
  • That is correct, is it possible this rule could conflict somehow (further down in the file: RewriteRule .* index.php/$0 [PT] ) – amcc Feb 10 '11 at 17:40