问题
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
回答1:
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]
来源:https://stackoverflow.com/questions/12875284/language-parameter-rewrite-with-mod-rewrite