多语言站点,子目录作为语言(RewriteRule)
对于我的网站,我想将我的网址重写为:
www.xxx.com/en/index.php 而不是 www.xxx.com/index.php?language=en
www.xxx.com/nl/index.php 而不是 www.xxx.com/index.php?language=nl
www.xxx.com 应该是 www.xxx.com/en/
这实际上有效我已经添加了这些重写规则
<代码> RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.xxx\.com(\/?)$
RewriteRule (.*) http://www.xxx.com/en/$1 [R=302,L]
RewriteRule ^(nl|en)/(.*)$ $2?language=$1&%{QUERY_STRING} [L]
添加 R=302 是为了测试目的
上面给出的 RewriteCond 和 RewriteRule 是否足够好,或者是否有其他可能更短或更好的方法将 .com/ 重写为 .com/en/
如果 url 被编辑为不支持的语言存在我希望该用户重定向到英语。
示例
请求 www.xxx.com/es/index.php,该语言不存在或未给出语言我希望用户重定向到 www.xxx.com/en/index.php
我尝试了以下操作:
<代码> RewriteRule ^([^n][^l]|[^e][^n])/(.*)$ en/$2%{QUERY_STRING} [L,R=302]
这在某些情况下有效,但如果输入 www.xxx.com/ne/index.php,则它被认为是有效的并且不会被重写。 www.xxx.com/index.php 也没有重写为 www.xxx.com/en/index.php
有人可以帮我解决这个问题吗?
提前致谢!
For my website i want to rewrite my url to:
www.xxx.com/en/index.php instead of www.xxx.com/index.php?language=en
www.xxx.com/nl/index.php instead of www.xxx.com/index.php?language=nl
www.xxx.com should be www.xxx.com/en/
This actually works i have added these rewrite rules
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.xxx\.com(\/?)$
RewriteRule (.*) http://www.xxx.com/en/$1 [R=302,L]
RewriteRule ^(nl|en)/(.*)$ $2?language=$1&%{QUERY_STRING} [L]
The R=302 is added for testing purposes
Are the above given RewriteCond and RewriteRule good enough or are there other, maybe shorter or better ways to rewrite .com/ to .com/en/
If the url is edited to a language that does not exists i want this user to be redirect to english.
Example
www.xxx.com/es/index.php is requested, this language does not exists or no language is given i want the user to be redirect to www.xxx.com/en/index.php
I tried the following:
RewriteRule ^([^n][^l]|[^e][^n])/(.*)$ en/$2%{QUERY_STRING} [L,R=302]
This works in some cases but if www.xxx.com/ne/index.php is entered it is considered as valid and not rewritten. www.xxx.com/index.php is also not rewritten to www.xxx.com/en/index.php
Could someone help me to fix this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个规则:
Try this rule: