【发布时间】:2010-08-10 15:01:42
【问题描述】:
对于我的网站,我想将我的网址重写为:
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
有人可以帮我解决这个问题吗?
提前致谢!
【问题讨论】:
标签: .htaccess mod-rewrite