404 page browser language with mod_rewrite as

I am trying to create 404 pages (also other errors), depending on the language, solely based on the Apache mod_rewrite rules, evaluating the Accept-Language client HTTP header. I managed to show the correct pages (default English) using these rules:

RewriteEngine on
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule (.+) /esp/error404.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.+) /eng/error404.php [L]

My problem is that I would like to support 404 errors, and I understand that redirecting does not allow this type of flag. I am by no means 100% sure if it really costs SEO wise, since it is better not to have 404s at all, but I thought it would be more logical and support logical sequences, etc., but I just can not understand how to achieve this through apache and HTTP: Accept-Language.

Any comments would be mostly appreciated.

+3
3

Apache.

ErrorDocument :

ErrorDocument 404 /parseme.php

/parseme.php :

RewriteCond %{REQUEST_FILENAME} ^/parseme\.php$
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule (.+) /esp/error404.php [L]

RewriteCond %{REQUEST_FILENAME} ^/parseme\.php$
RewriteCond %{HTTP:Accept-Language} ^eng [NC]
RewriteRule (.+) /eng/error404.php [L]

, 404 .

+4

. , .

, 404 . , - ... parseme.php , . , , , , , . :

ErrorDocument 404 /error_404.php

RewriteEngine on
# If spanish... use spanish error page
RewriteCond %{REQUEST_FILENAME} ^/error_404\.php$
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule (.+) /esp/error404.php [L]

# If previous did not match - any language (note [L] flag on previous rule) use english
RewriteCond %{REQUEST_FILENAME} ^/error_404\.php$
RewriteRule (.+) /eng/error404.php [L]
+2

Accept-Language, . , .

PHP, mod_rewrite .

0

Source: https://habr.com/ru/post/1728392/


All Articles