Forum Moderators: phranque

Message Too Old, No Replies

.htaccess error docs and subdomains

Use same error docs in subdomain as main site

         

Johnathon222

8:37 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



Hi,

what is the best way of using the same custom error docs in your subdomain as in your main site? I'm sure this question has come up before many times but I can't yet find a workable answer:

I have custom error docs (specified in my main .htaccess) which work fine in my main site

in my subdomain say chat.mysite.com/ these don't work,
now I can sort of get them to work by creating another .htaccess for the subdomain's directory and specifying a full URL to the error doc on the main site like:

[mysite.com...]

but this is a very clumsy way and brings up that URL in the browser rather than just returning the error which is not what I want.

For some reason specifying a full internal path like:

/home/myaccount/htmlfiles/myerrordocs/notfound.html does not work either in the subdomain's htaccess

Any ideas on a elegant solution (I can't Telnet in to create symlinks which I read about in a similar thread)

thanks a lot

jdMorgan

9:37 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be aware of the difference between URLs and server filepaths -- not the same thing at all, even if they lead to the same content in the end. Some directives want URLs, some want local URL-paths, and some want local filepaths.

You might want to post an example of your basic ErrorDocument directive -- it should work by default as long as your subdomains are pointed to subdirectories beneath you main domain's document_root.

Jim

Johnathon222

11:19 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



ok here is what I have in my main site's htaccess:

# error documents
ErrorDocument 403 /myerrordocs/notallowed.html
ErrorDocument 404 /myerrordocs/notthere.html

this will just return:

"Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

when a 404 is encountered in a subdomain

thanks

jdMorgan

11:45 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> it should work by default as long as your subdomains are pointed to subdirectories beneath you main domain's document_root.

What you haver there should work if your subdomains are pointed to subdirectories below the directory with your .htaccess ErrorDocument directives. How are your subdomains implimented? Where are the files located in realtion to document_root and in relation to your .htaccess file?

This is a little confusing because subdomains are URL terms, and I'm asking for file locations, but I hope it's clear enough.

Jim

Johnathon222

12:08 am on Jun 24, 2004 (gmt 0)

10+ Year Member



hi yes the subdomains just exist as folders within public_html, the main .htaccess file and the error documents folder also live in public_html

So yes in that sense, the error documents should work within the subdomains folders, but they do not

jdMorgan

12:20 am on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, another question...

Do you have RewriteRules in your existing .htaccess that redirect requests for subdomains to these subdirectories? (If so, it may be that these rules override your attempts to use a common file, and need to be changed. On the other hand, if you have mapped the subdomains to your subdirectories at the server config level, then you'll probably need to make the change there.)

Jim

Johnathon222

12:34 am on Jun 24, 2004 (gmt 0)

10+ Year Member



Hi There's just 1 rewrite rule stopping hotlinking of jpg,gif,png etc from external sites.

The rewrite allows subdomains for my site to access these graphics as well. Theres nothing else too fancy in the .htaccess file

Unfortunately I dont have access to a server config level.

I think this a fairly common problem, and have read a couple of things of people experiencing this

thanks for your time

jdMorgan

2:08 am on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, well it sounds like the server is configured to point the subdomains to a subdirectory of your main site's document root, assigning that subdirectory as the document root for the subdomain. If this is the case, then your error documents are probably not "visible" to http accesses in those subdomains. That is, although the server filepath-view allows you to navigate "up" from a subdomain's subdirectory, this is not true if the navigation is via URL.

One thing that would indicate this is if your main .htaccess file's anti-hotlinking protection *does not* also protect the subdomains - that's easy enough to test.

The cure (if this is the problem) is to ask your host to point all subdomains to your main directory, and let *you* sort them out into subdirectories using .htaccess. There are several recent posts here on how to map subdomains to subdirectories using mod_rewrite in .htaccess [webmasterworld.com].

Jim

Johnathon222

3:20 am on Jun 24, 2004 (gmt 0)

10+ Year Member



Jim, yes it does protect graphics in the subdomain, I've tested it several times, actually it was this site that helped me do that before.

Theres also some deny from IPs in the .htaccess. They are still 'honored' by the subdomain from my tests. So the problem seems confined to the error docs. The situation you describe sounds like what is happening.

I cannot 'break out 'of the subdomain doing:

subdomain.mysite.com/../

I can do this though(which is acutally annoying):

mysite.com/subdomain/../

which will return to the index page of the main site

I can also do this:

mysite.com/subdomain/nonexistantfile.html

and it will return the correct error document

So it seems you are right, I will ask the host, but I don't want them to break anything else on the site, so maybe just create some new error docs in the subdomain for now!

thanks