使用.htaccess重写多种语言的URL [英] Rewrite URL for multiple languages using .htaccess
本文介绍了使用.htaccess重写多种语言的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个多语言网站上工作,重写URL时遇到了一些麻烦。
I'm working on a multi-language website and I'm having a little trouble with rewriting URLs.
我必须有这样的东西:
1) mysite.com/en
2) mysite.com/en/product-one
3) mysite.com/en/product-one/id25/title-page-fake.html
4) mysite.com/en/login.php
URL重定向到:
1) mysite.com/index.php
2) mysite.com/index.php
3) mysite.com/item.php?id=25
4) mysite.com/login.php
我的.htaccess文件当前如下所示:
My .htaccess file currently looks like this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.+/{0,0})$ $1/index.php [NC]
RewriteRule ^([a-z0-9\-]+/)(.*)$ $2 [NC]
RewriteRule ^id(\d+)\/.*$ item.php?id=$1&%{QUERY_STRING} [L]
可以工作,但是会抛出异常:
works, but throws exceptions:
超出请求由于可能的配置错误,限制了10个内部重定向。如有必要,使用 LimitInternalRecursion增加限制。
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
推荐答案
确定,请尝试以下规则:
Ok try this rule:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# requirements 1 & 2
RewriteRule ^en(/product-one)?/?$ /index.php [L,NC]
# requirement # 3
RewriteRule ^en/product-one/id([0-9]+) /item.php?id=$1 [L,NC,QSA]
# requirement # 4
RewriteRule ^en/([^.]+\.php)$ /$1 [L,NC]
让我知道它是否有效我也可以建议其他规则。
Let me know if it works then I can suggest other rule also.
这篇关于使用.htaccess重写多种语言的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文