homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

.htaccess Custom ErrorDocument problem after multiple conditions
.htaccess ErrorDocument do not work after multiple conditions

5+ Year Member

Msg#: 4208969 posted 7:29 pm on Sep 29, 2010 (gmt 0)


I have a problem with my custom errorpage (ErrorDocument). First, please have a look at my current .htaccess file:

# needs to stay inline
Options +Indexes +FollowSymlinks -MultiViews
Options -Indexes

RewriteEngine on

DirectoryIndex index.php

# REDIRECT Force requests for named index files to drop the index file filename, and force www to avoid redirect chains:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php[45]?)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/([^\.]+)\.php\ HTTP/
RewriteRule ^(en|de|ar)/([^.]+)\.php$ http://www.domain.com/$1/$2 [R=301,L]

# REDIRECT all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# REWRITE url to filepath
RewriteRule ^(en|de|ar)/([^/.]+)$ /$1/$2.php [L]

# custom errorpages
ErrorDocument 404 /404.html

Short Summary
I have three language folders and (en, de, ar) and multiple files (PHP) in each folder. My .htaccess helps me to work with extensionless URLs.

My Problem:
I just tried to add a custom errordocument to that .htaccess file. Unfortunately it only works for URL typos within root, but not within my three language folders.

I've tried several things to fix this...but here I am.
Can somebody help me out?

Thanks in advance.

[edited by: tedster at 4:36 pm (utc) on Sep 30, 2010]
[edit reason] member requested fix [/edit]



WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4208969 posted 2:21 pm on Sep 30, 2010 (gmt 0)

You've declared a server-relative path to your 404 ErrorDocument instead of a directory-relative path, which means that all 404 errors will serve domain.com/404.html regardless of the requested subdirectory. Is that NOT what you want? What is the specific problem - What result did you want?

Your second rewriterule should be unnecessary, as the first one should already handle all subdirectories, including the language subdirectories. I'd suggest that you comment-out that second rule and test. If language subdirectories can still be requested with .php-extension URLs and don't get redirected to remove the ".php", then something is wrong with your first rule or with the "RewriteOptions inherit" setting.

You can eliminate the first rewritecond from your third rule by modifying its second rewritecond to
RewriteCond %{HTTP_HOST} !^(www\.domain\.com)?$
This is simply a shorter/faster equivalent method.


[edited by: tedster at 4:37 pm (utc) on Sep 30, 2010]
[edit reason] member requested fix [/edit]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved