.htaccess Question Regarding Subdirs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

.htaccess Question Regarding Subdirs

Post by volomike »

On my shared hosting plan, I have my site as mysite.com. But on my local Ubuntu workstation, I have my site as /var/www/mysite.com. Thus, if I want to do this in my .htaccess file for a Front Controller...

ErrorDocument 404 /mysite.com/front.php

...note that this works locally, but not on the shared hosting plan. My question is simple -- what's the trick where I can dynamically make that ErrorDocument statement work both on the shared hosting plan and my local Ubuntu workstation, such as use an .htaccess kind of variable or something?
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: .htaccess Question Regarding Subdirs

Post by volomike »

I tried all manner of:

Code: Select all

<Directory />
ErrorDocument ...blah blah...
</Directory>
 
<Directory /mysite.com>
ErrorDocument ...blah blah...
</Directory>
...and even tried Location directives, but this didn't work on my shared hosting provider for some reason.

In the end I had to poke around in my /etc/apache2/mods-available and /etc/apache2/mods-enabled directories locally on my workstation at home and do experimentation to find modules that were on my remote host but were not on my host. Thus, I ended up with the following solution that works at least for me. You may wish to replace "expires_module" with some other kind of "something_module" in your situation.

Code: Select all

<IfModule expires_module>
ErrorDocument 404 /front.php
</IfModule>
 
<IfModule !expires_module>
ErrorDocument 404 /mysite.com/front.php
</IfModule>
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess Question Regarding Subdirs

Post by alex.barylski »

If my previous answer doesn't give you what you need, you might try the Linux forum and VladSun will likely answer you in more detail, he's helped me several times in with everything Linux.

You shared hosting account, I'm wondering if it has ErrorDocument disabled...I would try that rewrite rule I supplied and see if that works.
Post Reply