浏览器语言基于404页的mod_rewrite与如何 [英] Browser language based 404 pages with mod_rewrite how to

查看:94
本文介绍了浏览器语言基于404页的mod_rewrite与如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成依赖于语言的404(也有其他错误)通过评估客户端的HTTP Accept-Language头完全基于Apache的mod_rewrite规则页。我已经成功地显示正确的页面(默认的英文)这个规则:

I am trying to generate language dependant 404 (also other errors) pages purely based on Apache mod_rewrite rules by evaluating the clients HTTP Accept-Language header. I've managed to show the correct pages (english default) with this 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]

我的问题是,我想保持404错误,我知道重定向不允许这种类型的标志。我在任何情况下,不是100%肯定它是否真的值得SEO明智的,因为它可能是最好不要有404可言,但我认为,这将是更符合逻辑和维护日志保持一致,等等,但我只是想不通怎么实现通过Apache和HTTP:接受语言

My problem is that I would like to maintain 404 errors and I understand redirect does not allow this type of flag. I am in any case not 100% sure if it's really worth SEO wise as it might be better not to have 404s at all, but I thought that it would be more logical and maintain logs consistent, etc, but I simply can't figure how to achieve that via apache and HTTP:Accept-Language.

任何评论都将大部分AP preciated。

Any comments would be mostly appreciated.

推荐答案

您可以使用Apache的默认错误处理程序做到这一点。

You could use Apache's default error handler to do this.

应该可以定义像这样的的ErrorDocument:

It should be possible to define an ErrorDocument like so:

ErrorDocument 404 /parseme.php

,然后做请求 /parseme.php 像这样一个语言相关的重定向:

and then do a language-dependent redirect for requests to /parseme.php like so:

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头,并以正确的语言错误页面了。

I have never tried this but this should give you a 404 header, and the error page in the correct language, too.

这篇关于浏览器语言基于404页的mod_rewrite与如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆