语言参数改写与mod_rewrite的 [英] language parameter rewrite with mod_rewrite
本文介绍了语言参数改写与mod_rewrite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助,做mod_rewrite的事情多到URL程序上:
-
如果URL以EN,ES PT-BR开始,将其删除,并添加?LANG = $ 1
-
如果URL没有下次有'网/'在里面,添加它。
-
如果该URL为空,进入网络/ EN /
-
他们没有实际上应该重写URL
这意味着:
http://www.domain.com/en>> http://www.domain.com/web/?lang=en
http://www.domain.com/en/mobile>> http://www.domain.com/mobile/?lang=en
解决方案
尝试:
RewriteEngine叙述在#这是prevent从循环的规则,他们只工作作为拍
的RewriteCond%{ENV:REDIRECT_STATUS} 200
重写规则^ - [L]#如果url为空,进入网络/ EN /
重写规则^ /?$ / WEB /?LANG = EN [L,QSA]#如果URL以EN,ES PT-BR开始,将其删除,并添加?LANG = $ 1,有/网络
重写规则^ /(EN | ES | PT-BR)?/网络(1 /?.*)$ / WEB $ 2 / LANG = $ [L,QSA,R]#如果URL以EN,ES PT-BR开始,将其删除,并添加?LANG = $ 1,没有/网络
重写规则^ /??(EN | ES | PT-BR)/ $ / WEB /郎1 = $ [L,QSA,R]#如果URL以EN,ES PT-BR开始,将其删除,并添加?LANG = $ 1,其他一切
重写规则^ /(EN | ES | PT-BR)?(?+)?/?/ 1 / $ 2 / LANG = $ [L,QSA,R]
I need some help with mod_rewrite doing multiple things to the url procedurally:
If the url starts with en,es,pt-br, remove it and add ?lang=$1
If the url does not next have 'web/' in it, add it.
If the url is blank, go to 'web/en/'
None of them should actually rewrite the url
This means:
http://www.domain.com/en >> http://www.domain.com/web/?lang=en
http://www.domain.com/en/mobile >> http://www.domain.com/mobile/?lang=en
解决方案
Try:
RewriteEngine On
# This is to prevent the rules from looping, they only work as on-shot
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
# If the url is blank, go to 'web/en/'
RewriteRule ^/?$ /web/?lang=en [L,QSA]
# If the url starts with en,es,pt-br, remove it and add ?lang=$1 ,has /web
RewriteRule ^/?(en|es|pt-br)/web(/?.*)$ /web$2/?lang=$1 [L,QSA,R]
# If the url starts with en,es,pt-br, remove it and add ?lang=$1 ,has no /web
RewriteRule ^/?(en|es|pt-br)/?$ /web/?lang=$1 [L,QSA,R]
# If the url starts with en,es,pt-br, remove it and add ?lang=$1 ,everything else
RewriteRule ^/?(en|es|pt-br)/(.+?)/?$ /$2/?lang=$1 [L,QSA,R]
这篇关于语言参数改写与mod_rewrite的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文