Ar. Lie Ar. Lie - 1 year ago 171
PHP Question

htaccess : 2 differents 404 Errors files (or content)

I am using a .htaccess file to catch ErrorDocument. Now, I have :

ErrorDocument 404 /errors/error404.php


It works great, but now, I want another error 404 file (or another content for this file), if the previous url contained "eu".

ErrorDocument 404 /errors/error404.php
<!-- If URL contains "eu", do : -->
ErrorDocument 404 /errors/eu_error404.php


Is this possible ? Or can I catch the URL where I came to execute differents include with PHP ?

I would like to avoid
$_SESSION
..

I saw things like :
$_SERVER['HTTP_REFERER']


Can someone explains me :) ?

Answer Source

Save your code and try the following code :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (eu)+
#the line above will catch any request contains eu
RewriteRule ^(.*)$ /errors/eu_error404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(eu)+
#the line above will exclude any request contains eu
RewriteRule ^(.*)$ /errors/error404.php
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download