Forum Moderators: phranque
I want [subdomain.domain.com(...] to point to [(www).domain.com...]
i.e. I want *any* subdomain (besides "www" or a nonexistent one) typed in/linked to to be used as the sole script parameter for a db lookup.
This is my server, so I have full access to everything. Wildcards are on for subdomains for this domain. About 50 domains/sites are hosted (all mine, not a hosting company or anything).
Here is the code in my .htaccess of the root document directory for the domain I am working with:
Options +FollowSymLinks
RewriteEngine ON
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com
RewriteRule /.* [domain.com...] [L]
I have Canonical names turned on in httpd.conf
All I get is a 500 error. Here is the line from the error_log:
[Mon May 23 12:29:17 2005] [error] [client *.*.*.*] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
I do not see 'RewriteOptions MaxRedirects' in the config.
In httpd.conf i have this for this VirtualHost:
....
ServerName www.domain.com
ServerAlias *.domain.com
....
What am I missing here? This is getting extremely frustrating!
Options +FollowSymLinks
RewriteEngine ON
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com
RewriteRule .* [domain.com...] [L]
When I try with a beginning slash on the RewriteRule pattern, it just goes to [subdomain.domain.com...] without any sort of redirect.
I am not concerned with review.php being called in the address bar itself (whether typed in or linked to).
My only concern is that the subdomain becomes a parameter for the script and it seems no matter what I try (including your example as a desperate attempt), I get a 500 internal error.
Perhaps your reply went over my head...
RewriteEngine ON
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com
RewriteRule .* /reviews.php?site=%1 [L]
(the missing space appears to be a bug in BestBBS. It eats space characters in front of a "!".)
Again, bird's code will loop unless an exclusion for reviews.php is added. For the sake of a simple exmlanation, you may consider mod_rewrite in an .htaccess context to be recursive; Any new URL you rewrite to will be run through the .htaccess code again. In your case, this creates a loop and the server 'times out' with the 'redirectiion limit' error message.
Jim
I hear what you are saying Jim, and see the logic of it. The error in the log is clear to me now that is a loop.
I tried the line you suggested but it still came up as a 500 error.
I was using the code in .htaccess
I moved all of the rewrite code to the httpd.conf directly for that domain in its <virtualhost> entry and........ it works like a charm :)
Any idea why it behaves so differently when in .htaccess?
I assume the rewrite conditions throw this off since they run through the conditions themselves.
Can I exclude images and anything else you may think of from this rule/condition, so they load normally?
Thanks guys, I really appreciate this :) This is my first time playing with mod_rewrite; I've been reading up on it all weekend and this forum has been the most resourceful so far for the beginner.
mod_rewrite code is not usually directly 'portable' between .htaccess and httpd.conf; The URLs 'seen' and tested by RewriteRule in .htaccess are 'localized' to the directory in which that .htaccess file is located. For example, the URL http:www.example.com/foo/bar/index.html is seen as "/foo/bar/index.html" in httpd.conf, as "foo/bar/index.html" in the .htaccess file located at "/.htaccess", as "bar/index.html" in the .htaccess file located in at "/foo/.htaccess", and as "index.html" by the .htaccess file in "/foo/bar/" -- This is why .htaccess is referred to as a "per-directory" configuration file.
Jim