Forum Moderators: phranque

Message Too Old, No Replies

Apache, rewrite_mod, unlimited domains & unlimited subdomains

         

jkari

6:38 pm on Apr 28, 2004 (gmt 0)

10+ Year Member



I am quite a newbie with this mod rewrite. I found it anyhow great.

I am having directories for domains at:
/home/www
(like /home/www/domain1.com, /home/www/domain2.fi...)

Here is my rewrite_mod code:


# Point addresses like http://domain1.com/something
# to /home/www/domain1.com/something
RewriteCond /home/www/%{HTTP_HOST} -d
RewriteRule ^(.*) /home/www/%{HTTP_HOST}$1 [L]

# Point addresses like
# http://sub.domain1.com/something to
# /home/www/domain1.com/sub/something
RewriteCond %{HTTP_HOST} ^([^.]+)\.(.*\..*)$
RewriteRule ^(.*) /home/www/%2/%1$1

This works most cases fine. But if there is directory:
/home/www/domainx.com/www/somedir
and I try to open it by typing:
[domainx.com...]
it wont work. Anyhow [domainx.com...]
will work!

Error message that I get is:

An error occurred while loading [domainx.com...]
Unknown host domainx

What might be the problem? And how to fix it. And also, am I doing this sensible way at all?

jdMorgan

9:54 pm on Apr 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jkari,

Welcome to WebmasterWorld [webmasterworld.com]!

This missing trailing slash problem would normally be fixed by Apache mod_dir, but it's possible that your host has UseCanonicalName on, which often causes this problem.

You can use a technique something like this to detect and fix a missing trailing slash:


# If the requested URL-path does not end with a dot followed by anything other than a
# slash (signifying that it ends in a filename)
RewriteCond %{REQUEST_URI} !\.[^/]+$
# and it does not end in a slash (which would signify that it is a directory index request)
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash
RewriteRule (.*) /$1/

This is meant as an example only. It might work if placed before your other code, or it might not. It might need to be modified to work with your specific site set-up. Either way, it is sort of a band-aid approach. If you (or your hosting provider) can set UseCanonicalName off in httpd.conf without breaking the rest of your site, try that first. With UseCanonicalName off, mod_dir should fix missing slashes automatically.

Ref:
UseCanonicalName [httpd.apache.org] documentation
Apache mod_dir [httpd.apache.org] documentation

Jim

jkari

3:49 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Thank you very much.

UseCanonicalName off
worked for this case.