Forum Moderators: coopster

Message Too Old, No Replies

Right syntax for the domain root

         

revrob

6:43 pm on Dec 11, 2010 (gmt 0)

10+ Year Member



My sites are hosted on a server where I have ftp access to a single folder, and my two registered domains are in two sub folders, to which the DNS servers point visitors for each domain.

host root--|
----domain1 - php script
----domain2 - php script

At the moment I have a php script in each domain root, which writes a "deny from" statement after certain types of bot visit, to the .htaccess file in the root folder but I want it to write to the .htaccess in the sub folder for thath domain. When it is written to the .htaccess in the ftp root, it doesn't seem to deny access to the subfolders.

The line in the two domain php files, which is duplicated in the root of each domain subfolder, is

$file = '../.htaccess'; //edit for path to your htaccess file

This points back to the "top" .htaccess file, but any "deny from" statements added there don't seem to affect access to the sub domains.

Either - I need to get the correct syntax in my .htaccess file so that the "deny from IP address" lines in the top level .htaccess apply to the two domains hosted below it

Could someone advise please?

two dots obviously means the ftp root directory.
How do I go to the domain root and not the ftp host root?

What is the address of my domain root? Obviously not '../.htaccess'

Alternatively - what should I investigate to make the "deny from IP " list in the ftp root apply to both the domains below it?

Many thanks once again. I've only just moved to having two domains with my hosting package so am learning it all over again!

coopster

9:11 pm on Dec 15, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A little confusing ... but you want two .htaccess files, right? One for each domain? If so, first you need to make sure they are active and working and that you are allowed to AllowOverride [httpd.apache.org]. Once you have all that in order you need to make sure your updates are actually taking, meaning you have your script running with the proper authority and that the .htaccess file has permissions set accordingly.

Now, the best way to get to your domain's DOCUMENT_ROOT in PHP is to use the $_SERVER['DOCUMENT_ROOT'] superglobal index. It will be an absolute path.

revrob

10:39 pm on Dec 15, 2010 (gmt 0)

10+ Year Member



Thanks for the reply
I've already got the .htaccess files set up and working.

All I need is to know what my php script needs to say to write to them - at the moment it writes to the ftp root version of .htaccess, and I want it to write to my individual domain .htaccess files instead.

So I need to know what the line in one of my php files that currently says

$file = '../.htaccess'; //edit for path to your htaccess file

and writes to the ftp root .htaccess file
(by putting in a "deny from" statement for a bot IP address that has triggered the php bot trap)

should say so that instead it writes that information to the domain .htaccess file.

I'm afraid I don't understand how to translate your reference to
$_SERVER['DOCUMENT_ROOT'] superglobal index

into that php statement. Can you clarify please? Many thanks.

coopster

3:16 am on Dec 16, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$file = $_SERVER['DOCUMENT_ROOT'] . '/.htaccess';

rocknbil

5:49 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah the dot syntax will really throw you at times because it's not always "where the files are" it's "where the server tells you you are." Use Coopster's example (with one small exception, below.)

Let me give an example. Let's say you use mod_rewrite to do this.

RewriteRule ^my_widget_page$ /scripts/widgets/script.php

You would think you can reference files at the domain root like this.

../../../.htaccess

But . . . the server is telling the client (browser) you are still at the domain root

/my_widget_page

So, of course, the dot syntax takes you to a directory that likely doesn't exist (example)

/var/www/httpdocs/example.com/scripts/widgets/script.php

(Takes you into the var directory, "permission denied.")

By using the document root environment variable it will always lead to the precise location.

The exception I mentioned: some servers append the document_root with a trailing slash depending on the config, so it may be safe to do a right trim of / on the document root variable. Tried to locate Readie's post on this, couldn't find it. :-)

Matthew1980

7:05 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^^^

The post [webmasterworld.com] as Rocknbil is referring to I think.

But good advice there.

I always use the <base href="h t t p://www.mysite.com" /> so that the links always point to the correct part of the url, because from the way I have understood it, base prefixes the <a href=""> with whatever is defined in the base tag, this also helps with the mod rewrite side of things too.

Cheers,
MRb