Forcing Apache to not add / to end of URI

Forcing Apache to not add / to end of URI

am 05.01.2008 09:39:17 von Jason Carlton

For lack of a better word, I'm doing something really weird with my
site. I have a series of domain names parked on top of my primary
domain, then in PHP I'm using the $_SERVER['HTTP_HOST'] variable to
determine what domain was typed in. Based on the domain, I'm showing
slightly modified information.

For the sake of argument, let's say that the primary domain (the one
that's actually set up) is www.mydomain.com, and the one parked on it
is www.parkdomain.com.

If you go to www.parkdomain.com, it works fine. And if you go to a
subdirectory like www.parkdomain.com/directory/, it works fine, too.
But if you leave off that last / and just go to www.parkdomain.com/directory,
then you're redirected to www.mydomain.com/directory/ (adding the
slash)... which then shows incorrect information because
$_SERVER['HTTP_HOST'] changed.

I'm sure that there's a setting in Apache that's causing this, and I'm
not sure if I can disable it without making the directory without
the / stop working altogether. Any ideas on how to fix this?

TIA,

Jason

Re: Forcing Apache to not add / to end of URI

am 05.01.2008 10:40:38 von unknown

Post removed (X-No-Archive: yes)

Re: Forcing Apache to not add / to end of URI

am 05.01.2008 20:48:01 von HansH

"Jason Carlton" schreef in bericht
news:3b602d1d-aa4f-4c75-b3ea-31a1d8841543@j20g2000hsi.google groups.com...
> For lack of a better word, I'm doing something really weird with my
> site. I have a series of domain names parked on top of my primary
> domain, then in PHP I'm using the $_SERVER['HTTP_HOST'] variable to
> determine what domain was typed in. Based on the domain, I'm showing
> slightly modified information.
Virtualizing a single site for multiple domains is creative not weird,
really ;-)
Things do get fuzzy if the single site is a virtual host itself.

> For the sake of argument, let's say that the primary domain (the one
> that's actually set up) is www.mydomain.com, and the one parked on it
> is www.parkdomain.com.

> If you go to www.parkdomain.com, it works fine. And if you go to a
> subdirectory like www.parkdomain.com/directory/, it works fine, too.
> But if you leave off that last / and just go to
> www.parkdomain.com/directory,
> then you're redirected to www.mydomain.com/directory/ (adding the
> slash)... which then shows incorrect information because
> $_SERVER['HTTP_HOST'] changed.
I'ld say pritty normal behaviour under control of a setting likely out of
your control ...
http://httpd.apache.org/docs/2.2/mod/core.html#usecanonicaln ame

> I'm sure that there's a setting in Apache that's causing this, and I'm
> not sure if I can disable it without making the directory without
> the / stop working altogether. Any ideas on how to fix this?
Your first stop is at
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directorys lash

Try 'DirectorySlash Off' in /.htaccess
It should stop the server from adding -through redirect- a slash _only_ when
missing.

However, now your content manipulating script MUST be able to distinct files
from folders.

If the script cann't and you can not make it to, as a last resort you could
create a rewriterule in the same .htaccess to redirect while adding a slash
and preserve the domainname:
RewriteEngine ON
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule (.*) http:%{HTTP_HOST}%{REQUEST_URI}/ [L,QSA]
( Working setting may very per hoster ...)



Hans