Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess Custom ErrorDocument problem after multiple conditions

.htaccess ErrorDocument do not work after multiple conditions



7:29 pm on Sep 29, 2010 (gmt 0)

5+ Year Member


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]


2:21 pm on Sep 30, 2010 (gmt 0)

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

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]


Featured Threads

Hot Threads This Week

Hot Threads This Month