Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.be$ [NC]
RewriteRule ^(.*)$ http://www.example.be/ [R,L]
RewriteCond %{HTTP_HOST} !^www\.example\.be
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.be/ [NC]
RewriteRule ^(.*)$ http://www.example.be/index.php?mod=routes&gemeente=%1 [L,R]
RewriteCond %{HTTP_HOST} !^www\.example\.be
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.be/([^\.\?/]+)$ [NC]
RewriteRule ^(.*)$ http://www.example.be/index.php?mod=routes&gemeente=%1&route=%2 [L,R]
The first part results in the following: when you go to example.be, you will be redirected to www.example.be. That's fine.
But the stuff under it won't work.
The site is about tours, and there are different cities, so I would like the following:
http://[city].example.be shows http://www.example.be/?mod=routes&gemeente=[city]
AND:
http://[city].example.be/[TOUR_NAME] shows http://www.example.be/?mod=routes&gemeente=[city]&route=[TOUR_NAME]
But the code I pasted at the top of this message won't work for that.
Again, sorry for the bad English, I hope you understand it :)
[edited by: jdMorgan at 11:57 pm (utc) on Mar. 21, 2005]
[edit reason] Removed specifics per TOS. [/edit]
Welcome to WebmasterWorld!
HTTP_HOST contains only the requested hostname, and an optional port number. It does not contain any part of the requested URI. Therefore, your last rule would never match.
Having fixed that, we still need to change the order of the second two rules, to put the longer, more-specific rule first.
I also changed the first rule to a 301-redirect, which is necessary to avoid problems with search engines choosing the wrong domain name to list your site. Also, I changed the second two rules to internal rewrites, so as to 'hide' them -- otherwise, your site structure would be exposed. This may or may not be what you want.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.be [NC]
RewriteRule ^(.*)$ http://www.example.be/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.be [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.be [NC]
RewriteRule ^([^./]+)$ /index.php?mod=routes&gemeente=%1&route=$1 [L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.be [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.be [NC]
RewriteRule .* /index.php?mod=routes&gemeente=%1 [L]
Jim