本文介绍了使用.htaccess重写多种语言的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个多语言网站上工作,重写URL时遇到了一些麻烦。
I'm working on a multi-language website and I'm having a little trouble with rewriting URLs.
我必须有这样的东西:
1) mysite/en 2) mysite/en/product-one 3) mysite/en/product-one/id25/title-page-fake.html 4) mysite/en/login.phpURL重定向到:
1) mysite/index.php 2) mysite/index.php 3) mysite/item.php?id=25 4) mysite/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
发布评论