subdomain rewrite & setting of environment variable

Using a single web hosting account to host multiple sites

Postby richardk » Tue Sep 15, 2009 5:39 pm

Right, i misunderstood. Where are you getting the test.sites.example.com/clients/test/blog/wp-admin/install.php URL? After a redirect or in the source of the page. I think you'd have to change the base path (in Wordpress), the redirect or the HTML link.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nkj » Wed Sep 16, 2009 10:06 am

richardk wrote:Right, i misunderstood. Where are you getting the test.sites.example.com/clients/test/blog/wp-admin/install.php URL? After a redirect or in the source of the page. I think you'd have to change the base path (in Wordpress), the redirect or the HTML link.


I had to revert your last recommended changes as it was preventing access to files outside of the files/directories from the AliasMatches. So I'm back to the config I posted on "Mon Sep 14, 2009 6:33 am".

So, we can use a simpler example.

Aside from the directories defined in the AliasMatches, the user can make their own local directories in their htdocs area and these should be accessible like normal. (ie. look for index files when just a directory name is specified). For example if I make the directory/file:

Code: Select all
/data/clients/test/mydir/
/data/clients/test/mydir/index.html


I should be able to access it via:


Code: Select all
http://test.sites.example.com/mydir/


However when I do this I get a 403 error. To correct this, if I go to:

Code: Select all
http://test.sites.example.com/mydir/index.html


The file loads correctly. I'd like specifying just the directory name to work as would be expected (search based on DirectoryIndexes directive). If no index files are found, then it should display the 403 (because i don't want to list the contents of a directory)... but if an index file is found, it should be executed.

Another problem I have, is currently if I access:

Code: Select all
http://test.sites.example.com/cms


(Note the lack of a trailing / ) - This executes the correct index.php (in the specified directory), however it doesn't seem to register the fact that it's current dir is now /cms/ so all relative URLs (ie. css/style.css or logo.jpg) are all looked for based on the webroot and not webroot/cms/. (ie. the file is not found /logo.jpg but it is located in /cms/logo.jpg )... when I add the trailing slash to the URL everything behaves normally. Any idea how to fix this? maybe some way to force the trailing / or... ?



If I can get these two issues resolved, it may indirectly fix the problem I'm having with the wordpress blog - I can't really test the wordpress blog directly until I make sure this basic behavior is corrected.

Thanks for your help!
-Nick[/code]
nkj
 
Posts: 21
Joined: Fri May 15, 2009 11:32 am

Postby richardk » Wed Sep 16, 2009 2:26 pm

I'd like specifying just the directory name to work as would be expected (search based on DirectoryIndexes directive). If no index files are found, then it should display the 403 (because i don't want to list the contents of a directory)... but if an index file is found, it should be execute

Do you have a <Directory> that's configuration could be overwriting it?

(Note the lack of a trailing / ) - This executes the correct index.php (in the specified directory), however it doesn't seem to register the fact that it's current dir is now /cms/ so all relative URLs (ie. css/style.css or logo.jpg) are all looked for based on the webroot and not webroot/cms/. (ie. the file is not found /logo.jpg but it is located in /cms/logo.jpg )... when I add the trailing slash to the URL everything behaves normally. Any idea how to fix this? maybe some way to force the trailing / or... ?

Is /cms the only directory you have that problem with? What about /flash? It might be that the the AliasMatch is not taken into account.
Try replacing
Code: Select all
    RewriteCond %{DOCUMENT_ROOT}/clients/%1%{REQUEST_URI}/ -d

with
Code: Select all
    RewriteCond %{DOCUMENT_ROOT}/clients/%1%{REQUEST_URI}/ -d [OR]
    RewriteCond /clients/%1%{REQUEST_URI}/ -F


Or if that doesn't work add
Code: Select all
RewriteCond /usr/local/staff/cmd/cmd/trunk/cmdv3%{REQUEST_URI}/ -d
RewriteRule ^(cms|flash|html|slideshow)(/.*[^/])?$ http://%{HTTP_HOST}$0/ [R=301,L]

after
Code: Select all
RewriteEngine On
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nkj » Thu Sep 17, 2009 7:46 am

Ok I managed to fix the /cms issue by just modifying the code to check if the URL ends in a /cms to reload the page with a /cms/ - this works fine.

So now really the only issue seems to be the accessing of a non-aliases directory. I'll give you a couple examples of the behavior, and also re-paste in my current config so it's clear what is set at the moment:


Code: Select all
/data/clients/test/mydir
aka.
/data/sites/sites.example.com/htdocs/clients/test/mydir/

(in the htdocs dir, 'clients' is actually a symlink to /data/clients/ - but i don't think this has any effect, just wanted to mention it in case).


in there i have an 'index.html'... so when I access:

Code: Select all
http://test.sites.example.com/mydir


I get a 404 error with the following log:

Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir HTTP/1.1" 301 349
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir/index.php HTTP/1.1" 404 321

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:28:12 2009] [error] [client 90.178.229.150] script '/data/sites/sites.example.com/htdocs/clients/test/mydir/index.php' not found or unable to stat


In this case it does not seem to make a difference if I specify /mydir or /mydir/ ... It looks for index.php only, even though my DirectoryIndex specifies index.php index.html index.cgi ...




As for the blog. I have the wordpress blog unpacked to:

Code: Select all
/data/clients/test/blog
aka.
/data/sites/sites.example.com/htdocs/clients/test/blog/


When I access:

Code: Select all
http://test.sites.example.com/blog/


I get a 403 and this in the logs:

Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:23:05 -0500] "GET /blog/ HTTP/1.1" 403 315

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:23:05 2009] [error] [client 90.178.229.150] Directory index forbidden by Options directive: /data/sites/sites.example.com/htdocs/clients/test/blog/




When I access:

Code: Select all
http://test.sites.example.com/blog


I get a 403 error, with this in the logs:

Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:35:25 -0500] "GET /blog HTTP/1.1" 301 348
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:35:26 -0500] "GET /blog/index.php HTTP/1.1" 302 -
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:35:26 -0500] "GET /clients/test/blog/wp-admin/install.php HTTP/1.1" 404 347

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:35:26 2009] [error] [client 90.178.229.150] File does not exist: /data/sites/sites.example.com/htdocs/clients/test/clients



In this case, it rewrites the URL in the browser as:

Code: Select all
http://test.sites.example.com/clients/test/blog/wp-admin/install.php


If I could somehow rewrite anything matching <url>/clients/%1% (%1% = 'test' in this case) then I could rewrite the url to be: http://test.sites.example.com/blog/wp-admin/install.php - I think (hope) this would work... Does this make sense?



Now what I did was manually put in:

Code: Select all
http://test.sites.example.com/blog/wp-admin/install.php


(removed clients/test/) ... This got me into the WP admin, I was able to setup the blog. However I then could not view it:

Code: Select all
http://test.sites.example.com/blog/


Code: Select all
==> httpd/sites.example.com-access_log <==
90.178.229.150 - - [17/Sep/2009:10:42:56 -0500] "GET /blog/ HTTP/1.1" 403 315

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:42:56 2009] [error] [client 90.178.229.150] Directory index forbidden by Options directive: /data/sites/sites.example.com/htdocs/clients/test/blog/




Here is my entire VHOST directive:


Code: Select all
<VirtualHost *:80>
    ServerName sites.example.com:80
    ServerAlias *.sites.example.com:80
    ServerAdmin webmaster@example.com
    DocumentRoot /data/sites/sites.example.com/htdocs
    ErrorLog logs/sites.example.com-error_log
    CustomLog logs/sites.example.com-access_log common

    DirectoryIndex index.php index.html index.cgi

    AliasMatch ^/clients/[^/]+/(index\.php)?$ "/usr/local/staff/cmd/cmd/trunk/cmdv3/index.php"
    AliasMatch ^/clients/[^/]+/(confirmation\.php)$ "/usr/local/staff/cmd/cmd/trunk/cmdv3/confirmation.php"
    AliasMatch ^/clients/[^/]+/(contact\.php)$ "/usr/local/staff/cmd/cmd/trunk/cmdv3/contact.php"

    AliasMatch ^/clients/[^/]+/cms/?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/cms/index.php"
    AliasMatch ^/clients/[^/]+/cms/(.+)?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/cms/$1"
    AliasMatch ^/clients/[^/]+/flash/?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/flash/index.php"
    AliasMatch ^/clients/[^/]+/flash(/(.*))?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/flash/$2"
    AliasMatch ^/clients/[^/]+/html/?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/html/index.php"
    AliasMatch ^/clients/[^/]+/html(/(.*))?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/html/$2"
    AliasMatch ^/clients/[^/]+/slideshow/?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/slideshow/index.php"
    AliasMatch ^/clients/[^/]+/slideshow(/(.*))?$  "/usr/local/staff/cmd/cmd/trunk/cmdv3/slideshow/$2"

    Options +FollowSymlinks Indexes ExecCGI

    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^(www\.)?sites\.example\.com$    [NC]
    RewriteCond %{HTTP_HOST} ^(.+)\.sites\.example\.com$ [NC]

    RewriteCond %{DOCUMENT_ROOT}/clients/%1%{REQUEST_URI}/ -d

    RewriteRule ^/.*[^/]$ http://%{HTTP_HOST}$0/index.php [R=301,L]

    RewriteCond %{HTTP_HOST} !^(www\.)?sites\.example\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(.+)\.sites\.example\.com$ [NC]

    RewriteRule ^/.*$ /clients/%1$0 [QSA,E=CMD_SITE:%1,PT,L]

</VirtualHost>
nkj
 
Posts: 21
Joined: Fri May 15, 2009 11:32 am

Postby richardk » Thu Sep 17, 2009 9:54 am

I get a 404 error with the following log:
Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir HTTP/1.1" 301 349
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir/index.php HTTP/1.1" 404 321

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:28:12 2009] [error] [client 90.178.229.150] script '/data/sites/sites.example.com/htdocs/clients/test/mydir/index.php' not found or unable to stat

The mod_rewrite redirect adds index.php (the second access log entry should be for /mydir/). Replace
Code: Select all
http://%{HTTP_HOST}$0/index.php

with
Code: Select all
http://%{HTTP_HOST}$0/


If I could somehow rewrite anything matching <url>/clients/%1% (%1% = 'test' in this case) then I could rewrite the url to be: http://test.sites.example.com/blog/wp-admin/install.php - I think (hope) this would work... Does this make sense?

You can do that redirect
Code: Select all
    RewriteCond %{HTTP_HOST} !^(www\.)?sites\.example\.com$    [NC]
    RewriteCond %{HTTP_HOST} ^(.+)\.sites\.example\.com$ [NC]
    RewriteCond %1?$1 ^([^\?]+)\?\1$ [NC]
    RewriteRule ^/clients/([^/]+)(/(.*))?$ /$3 [R=301,L]

but you should find the script's (in this case Wordpress) base path and then the problem should not occur. (The redirect fixes the symptom not the problem.)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nkj » Fri Sep 18, 2009 5:35 am

richardk wrote:
I get a 404 error with the following log:
Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir HTTP/1.1" 301 349
xxx.xxx.xxx.xxx - - [17/Sep/2009:10:28:12 -0500] "GET /mydir/index.php HTTP/1.1" 404 321

==> httpd/sites.example.com-error_log <==
[Thu Sep 17 10:28:12 2009] [error] [client 90.178.229.150] script '/data/sites/sites.example.com/htdocs/clients/test/mydir/index.php' not found or unable to stat

The mod_rewrite redirect adds index.php (the second access log entry should be for /mydir/). Replace
Code: Select all
http://%{HTTP_HOST}$0/index.php

with
Code: Select all
http://%{HTTP_HOST}$0/



I think this is narrowing things down to the exact problem I'm having. Once a request finally gets to <url>/dir/ the DirectoryIndex directive never kicks in.

With the RewriteRule:
Code: Select all
RewriteRule ^/.*[^/]$ http://%{HTTP_HOST}$0/index.php [R=301,L]


I enter the URL:
Code: Select all
http://test.sites.example.com/mydir

which rewrites it as:
Code: Select all
http://test.sites.example.com/mydir/index.php

This is obviously the expected behavior from that rule. However if I enter the URL:
Code: Select all
http://test.sites.example.com/mydir/

(Notice the trailing slash), I get a 403 forbidden with this log entry:
Code: Select all
==> httpd/sites.example.com-access_log <==
xxx.xxx.xxx - - [18/Sep/2009:08:29:56 -0500] "GET /mydir/ HTTP/1.1" 403 316

==> httpd/sites.example.com-error_log <==
[Fri Sep 18 08:29:56 2009] [error] [client 213.220.219.188] Directory index forbidden by Options directive: /data/sites/sites.example.com/htdocs/clients/test/mydir/


Now, the latest change you suggested helps to clarify this point:

using the RewriteRule:
Code: Select all
RewriteRule ^/.*[^/]$ http://%{HTTP_HOST}$0/index.html [R=301,L]


I get the 403 error for both /mydir and /mydir/

So where I'm hitting the wall on this problem is with the failure to use the DirectoryIndex directive when confronted with a request to access a directory (a 'real' directory created by the user, not one of the AliasMatch directories. )

It seems to me that If this problem is resolved, perhaps the issue with the blog will either fix itself, or at least become more clear.
Thanks,
Nick
nkj
 
Posts: 21
Joined: Fri May 15, 2009 11:32 am

Postby richardk » Fri Sep 18, 2009 9:09 am

Do not specify an index file at all, when we fix the problem Apache can handle that.

What happens if you comment out the mod_rewrite and go to /clients/test/mydir/?
What happens if you comment out the AliasMatches (but not the mod_rewrite) and go to /mydir/?
What happens if you comment out both and go to /clients/test/mydir/?
Did you check for <Directory>s that could be conflicting?

Also add
Code: Select all
Options +Indexes

so you can see the directory.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nkj » Mon Sep 21, 2009 4:28 pm

richardk wrote:Do not specify an index file at all, when we fix the problem Apache can handle that.

What happens if you comment out the mod_rewrite and go to /clients/test/mydir/?
What happens if you comment out the AliasMatches (but not the mod_rewrite) and go to /mydir/?
What happens if you comment out both and go to /clients/test/mydir/?
Did you check for <Directory>s that could be conflicting?

Also add
Code: Select all
Options +Indexes

so you can see the directory.



Things seem to go wrong when I'm using the mod_rewrite rules. I can make a static vhost record for 'test.sites.example.com' and use everything but the mod_rewrite stuff and I have no problems. Maybe this is just too complicated to pull off? Maybe I will just need to make a static vhost record for each new site. The problem is this will mean thousands of records in the httpd.conf - instead of one vhost record to catch them all.

I did check everywhere and I don't see any Directory directive that could possibly be conflicting.

Thanks for all your help. Seems like maybe we've hit a dead end?
-Nick
nkj
 
Posts: 21
Joined: Fri May 15, 2009 11:32 am

Postby richardk » Tue Sep 22, 2009 9:12 am

Try replacing
Code: Select all
    Options +FollowSymlinks Indexes ExecCGI

with
Code: Select all
    Options FollowSymLinks Indexes ExecCGI
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nkj » Wed Sep 23, 2009 1:38 pm

richardk wrote:Try replacing
Code: Select all
    Options +FollowSymlinks Indexes ExecCGI

with
Code: Select all
    Options FollowSymLinks Indexes ExecCGI


Doesn't seem to change anything. At this point i've opted for the vhost record for each site. not ideal but at least i can rely on it to behave nicely with 3rd party apps (like wordpress).

Thanks for your help with this one. I'm very grateful.
-Nick
nkj
 
Posts: 21
Joined: Fri May 15, 2009 11:32 am

Previous

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 6 guests

cron