Jump to content

.htaccess ErrorDocument


Err

Recommended Posts

So I have an apache server with subdomains with subdirectories. I turn my directories into subdomains. So instead of example.site.com/mycoolsite it's mycoolsite.example.com. I do this with the .htaccess file with the below code.

RewriteCond %{HTTP_HOST} ^mycoolsite.site.com$ [NC]RewriteCond %{REQUEST_URI} !^/mycoolsite/RewriteRule ^(.*)$ /mycoolsite/$1 [L]

Great. Now it turns the directory into the subdomain. The problem now is that .htaccess can't reference the ErrorDocument I setup for my original subdomain. I can go to example.site.com/mycoolsite/aNonExistantDirectory/ and get the proper 404 I have setup, but when I try mycoolsite.site.com/aNonExistantDirectory/ I get the basic server 404 error page, not the one I have setup. Both are on the same server. To get around the problem, I can make a copy of the error documents and put them inside the /mycoolsite/ directory but I'm hoping I can simply reference the original error documents. The problem is, I don't know how to reference the error documents in /var/www/error/ to /var/www/mycoolsite/ I've tried:

ErrorDocument 404 ../error/index.php?p=404ErrorDocument 404 /www/error/index.php?p=404ErrorDocument 404 www/error/index.php?p=404ErrorDocument 404 error/index.php?p=404ErrorDocument 404 /error/index.php?p=404

None of those work. When try it without the first / or preceding .. it will display the error document line on the page. I'm stumped. I hope I included enough information, but if not, let me know.If I can't get my ErrorDocument's to work, would I be able to edit the first code above to allow for it?

Link to comment
Share on other sites

What about

ErrorDocument 404 /../error/index.php?p=404

or

ErrorDocument 404 /var/www/error/index.php?p=404

Link to comment
Share on other sites

When I try /../error/index.php?p=404 I get:Not Found The requested URL /mycoolsite/error/ was not found on this server. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request. /var/www/error/index.php?p=404:Not Found The requested URL /mycoolsite/error/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Edited by Err
Link to comment
Share on other sites

I figured it out... sort of; in that I came to compromise.I created a file named error.php, inside of that I have:

<?php  include('../error/index.php');?>

The above code includes the index.php file from the /error/ directory. Then all I had to do is configure my .htaccess file:

<Directory /var/www/mycoolsite>  ErrorDocument 404 /error.php?err=404  [etc...]</Directory>

Thanks for the help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...