Forum Moderators: phranque
I need to implement a special case in httpd.conf.
Here's what I have now:
ServerAlias *.domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^blog\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$
RewriteCond ^www\.domain\.com/member/%2!-d
RewriteRule ^(.*)$ /member/%2/$1 [L]
This works fine for allowing subdomains to work as:
[subdomain.domain.com...] which is rewritten as:
[domain.com...]
But I also need to rewrite:
[subdomain.domain.com...] OR
[subdomain.domain.com...]
to:
[domain.com...]
What do I need to change and/or add to make this happen?
Also, do I need to keep the final $1 in this line:
RewriteRule ^(.*)$ /member/%2/$1 [L
or change it so it doesn't prevent the last substitution?
Everything I've tried so far has either given me a 404 on
[subdomain.domain.com...] OR
[subdomain.domain.com...]
or else locked up Apache so it wouldn't restart!
Thanks in advance,
Frustrated
RewriteCond ^www\.domain\.com/member/%2 !-d
RewriteCond %{REQUEST_FILENAME}/member/%2 !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/member/%2 !-d
You will have to test to determine which is correct for your server configutration.
I can't comment on your new code, since you didn't post it. Please review and post any pertinent data from your server error log. It will often tell you exactly what's wrong.
Jim
When I replaced:
RewriteCond ^www\.domain\.com/member/%2!-d
with:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/member/%2!-d
and then with:
RewriteCond %{REQUEST_FILENAME}/member/%2!-d
there was no noticeable change in system behavior.
Everything that was woring before continued to work.
.
.
.
RewriteCond %{REQUEST_FILENAME}/member/%2!-d
RewriteRule ^(.*)$ /podcast/%2/$1 [L]
Here's my latest attempt at a rewrite rule:
RewriteRule ^/load\.mp3(.*)$ /load.php?f=$1 [L]
I just get a 404 error when I try to visit:
[subdomain.domain.com...]
The error log is empty. Literally. Zero bytes. But the access_log is huge (431MB). I tried to tail it from a command shell, but Webmin just comes back with "Page cannot be displayed". It does that with a lot of shell commands...
I suspect any error message are in the access_log. (?)
Does my last Rewrite Rule even make sense?
RewriteRule ^/load\.mp3(.*)$ /load.php?f=$1 [L]I just get a 404 error when I try to visit:
[subdomain.domain.com...]Is this code in httpd.conf or .htaccess? If in .htaccess, then remove the leading slash from the beginning of the RewriteRule pattern, as it is stripped from the local URL-path and will not be present. Therefore, a Rule in .htaccess with an anchored leading slash in the pattern will never match.
I cannot tell you which of the two variants of the "!-d" RewriteCond I posted will be correct for your server, only that the RewriteCond you had was wrong and won't work, as it's trying to use a canonical URL as a directory name, and see it exists as a directory. Directories, as a rule, don't ever start with "http://"
Terse, big hurry, please forgive typos, apologies... Gotta go.
Jim
RewriteRule ^/(.*) /new-path/$1
RewriteRule (.*) /new-path$1
In the second case, we do copy the leading slash into $1, and then use it in the substitution, so there's no need to add one there manually.
Which one you choose is largely a matter of style; I use the first form because I find it easier to remember to change them when I copy httpd.conf code to .htaccess, or vice-versa. But the point is to avoid adding an extra slash to the substitution URL, so either way will work.
Jim