Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite and wildcard DNS

         

Echil0n

10:03 am on May 28, 2007 (gmt 0)

10+ Year Member



I'm having problems with rewriterule. Ity's always a buit hit and miss, but I can't figure out why it's not working this time. I wan to change from having a load of arguments in the URL to having a directory/subdirectory structure. I have wildcard DNS enabled, and the code below rewrites every subdomain to an argument - eg: [blah.mydomain.net...] becomes [mydomain.net...]

RewriteCond %{HTTP_HOST}!^(www¦images)\.mydomain\.net$
RewriteCond %{HTTP_HOST}!^mydomain\.net$
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.net$
RewriteRule (.*) /home/mydomain/index.php?cal=%1

The problem is, I want to pass more paramaters, so [blah.mydomain.net...] becomes [mydomain.net...] I've tried using another rewrite rule, but I can't get it working. I *think* it should be something like this:

RewriteCond %{HTTP_HOST}!^(www¦images)\.mydomain\.net$
RewriteCond %{HTTP_HOST}!^mydomain\.net$
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.net$
RewriteRule ^rss/?$ /home/mydomain/index.php?cal=%1&act=rss [S,L]
RewriteRule (.*) /home/mydomain/index.php?cal=%1

Could anyone lend a hand?

g1smd

12:13 pm on May 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can only have one RewriteRule after a RewriteCond line if you want that Rule to be associated with those conditional tests.

Your second RewriteRule line has no associated RewriteCond line and therefore EVERY URL presented to it is written that way. I'm not sure if that is what you intended.

jdMorgan

3:56 pm on May 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll also need to add an exclusion to the second rule to prevent an 'infinite' rewriting loop.

The good news is that your second RewriteCond was redundant, in that the third *requires* a subdomain to be present, so you can delete it and reduce the number of necessary repeated RewriteConds:


RewriteCond %{HTTP_HOST} !^(www¦images)\.mydomain\.net
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.net
RewriteRule ^rss/?$ /home/mydomain/index.php?cal=%1&act=rss [L]
#
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteCond %{HTTP_HOST} !^(www¦images)\.mydomain\.net
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.net
RewriteRule (.*) /home/mydomain/index.php?cal=%1 [L]

Jim