2014-07-12 63 views
0

我想將除英文以外的所有語言重定向到另一個文件夾。如果你不是英語,你去www.webpage.com/work/你會去www.webpage.com/xx/work如何重定向到.htaccess中的文件夾?

現在我有這樣的代碼:

RewriteEngine on 
RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|co|cs|cy|da|de|dz|el|en|eo|et|eu|fa|fi|fj|fo|fr|fy|ga|gd|gl|gn|gu|ha|hi|hr|hu|hy|ia|ie|ik|in|is|it|iw|ja|ji|jw|ka|kk|kl|km|kn|ko|ks|ku|ky|la|ln|lo|lt|lv|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|na|ne|nl|no|oc|om|or|pa|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sd|sg|sh|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sv|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|uk|ur|uz|vi|vo|wo|xh|yo|zh|zu) [NC] 
RewriteRule .* www.webpage.com/en/ [R,L] 

但我想從/工作重定向/到/ XX /工作/

使用%1感謝

回答

1

您需要RewriteCond使用反向引用捕獲文本:

RewriteEngine on 

RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|co|cs|cy|da|de|dz|el|en|eo|et|eu|fa|fi|fj|fo|fr|fy|ga|gd|gl|gn|gu|ha|hi|hr|hu|hy|ia|ie|ik|in|is|it|iw|ja|ji|jw|ka|kk|kl|km|kn|ko|ks|ku|ky|la|ln|lo|lt|lv|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|na|ne|nl|no|oc|om|or|pa|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sd|sg|sh|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sv|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|uk|ur|uz|vi|vo|wo|xh|yo|zh|zu) [NC] 
RewriteRule ^$ /%1/work/ [R,L] 

RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|co|cs|cy|da|de|dz|el|en|eo|et|eu|fa|fi|fj|fo|fr|fy|ga|gd|gl|gn|gu|ha|hi|hr|hu|hy|ia|ie|ik|in|is|it|iw|ja|ji|jw|ka|kk|kl|km|kn|ko|ks|ku|ky|la|ln|lo|lt|lv|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|na|ne|nl|no|oc|om|or|pa|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sd|sg|sh|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sv|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|uk|ur|uz|vi|vo|wo|xh|yo|zh|zu) [NC] 
RewriteRule ^((?![a-z]{2}/).+)$ /%1/$1/ [R,L] 
+0

但還有更多頁面/ contact /,並非所有都是/ work /,我希望如果你把/ work /你會去/ en/work /和/ contact/to/en/contact/ – oriolclosa

+0

ok試試現在更新規則 – anubhava

+0

我明白了:www.webpage.com/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/404// – oriolclosa