网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站设计 > PHP
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 153.99.40.237
Old 2015-07-15, 08:31 PM
Abilene Abilene is offline
初级会员
 
Join Date: 2007-01-22
Posts: 1
Abilene 现在声名狼藉
Default Htaccess language Redirect 310 error

I have a two language site
Code:
Swedish side  www.site.com
English side  www.site.com/?lang=en
I'm using
Code:
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|ca|co|cs|cy|da|de|dz|el|en|eo|es|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|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.site.com/?lang=en [L]
To get all languages but Swedish to the www.site.com/?lang=en but I end up in a 310 loop. what is missing ?
Reply With Quote
  #2   IP: 153.99.6.125
Old 2015-07-15, 08:57 PM
Abita Springs Abita Springs is offline
初级会员
 
Join Date: 2010-10-23
Posts: 3
Abita Springs 现在声名狼藉
Default

You need to add a check for lang to make sure you don't loop.
Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} !(&|^)lang=
RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|ca|co|cs|cy|da|de|dz|el|en|eo|es|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|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 .* http://www.site.com/?lang=%1 [L]
Note that the %1 is a backreference to the 2 letter language code that matched in the previous RewriteCond. The other thing about the Rule to note is that a request like /something/file.html will get redirected to http://www.site.com/?lang=(2 letter language code). Essentially, the original path is lost. If you want to keep it, you need to match and use a backreference:

Code:
RewriteRule ^(.*)$ http://www.site.com/$1?lang=%1 [L]
If you want previous query strings to also get passed, for example, /something/file.php?a=b, you need to add QSA in the brackets so that it will get redirected to http://www.site.com/somthing/file.php?lang=(2 letter language code)&a=b.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PayPal 出错处理 Queen 电子商务 2 2014-11-15 11:03 AM
.htaccess 301 Redirect Packard 建站交流 1 2014-06-15 07:53 PM
htaccess 301 redirect tutorial yahoo 服务器环境搭建 0 2009-09-06 12:45 AM
How do I make custom 404 error documents? topvip 代码交流 0 2006-10-18 12:35 AM
.htaccess文件使用手册 topvip 服务器环境搭建 1 2006-01-17 01:44 PM

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:42 PM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.