Forum Moderators: phranque

Message Too Old, No Replies

conditional statements in .htaccess?

error pages - language versions

         

wizpl

3:47 am on Sep 25, 2006 (gmt 0)

10+ Year Member



Is it possible to display different error pages depending on a $_GET value or a pattern in an address.

I use this search friendly rewriting rule for a secondary language version of my site.


RewriteEngine On
RewriteRule ^pl/(.*)$ /$1?lang=pl

is it possible, when someone requests an address of a nonegsisting page but the addres contains "?lang=pl" or starts with "/pl/", that he gets an alternate language version of the 404 page?

thanks for help.

wizpl

4:56 am on Sep 25, 2006 (gmt 0)

10+ Year Member



ok, I've found a solution in php code of of an error page:


$referingpage = $_SERVER['REQUEST_URI'] ;
if (stristr($referingpage, '/pl/') ¦¦ stristr($referingpage, '?lang=pl'))
{...secondary lnguage...}
else
{...main language...}

so there's no need to change .htaccess

jdMorgan

4:57 am on Sep 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are several ways to do this.

You can use Apache's content negotiation -- see mod_negotiation -- to deliver content based on the browser's language preference settings.

You can also try declaring custom error pages, and rewriting those error pages just as you have done for your content:


ErrorDocument 404 /404.html
#
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /pl/
RewriteRule ^404.html$ /404_pl.html [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /en/
RewriteRule ^404.html$ /404_en.html [L]
#
RewriteRule ^pl/(.*)$ /$1?lang=pl

You can also use SSI includes, PERL, or PHP scripts to generate localized error pages.

Jim