我需要一些帮助mod_rewrite在程序上对url执行多项操作:
如果网址以en,es,pt-br开头,请将其删除并添加?lang = $ 1
如果网址下面没有“网络/”,请添加。
如果网址为空,请转到“web / en /”
他们都不应该实际重写网址
这意味着:
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
答案 0 :(得分:2)
尝试:
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]