douwa6220 2014-03-01 11:42
浏览 52
已采纳

htaccess将语言部分添加到现有重定向规则

I have quite a complex .htaccess with 30 redirect rules. Now the client wants to add language specific parts to the beginning of the urls.

Example: http://example.eu/sale should be http://example.eu/de/sale where "de" is the language code for one of the 5 languages.

I've found this:

RewriteRule ^(en|de|fr|ja|ru)/(.*)$  $2?language=$1 [L,QSA]

Is there a simple way to add this feature to existing rules? (Below is some of the existing rules)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.eu$ [NC]
RewriteRule (.*) http://example.eu/$1 [R=301,L]

RewriteRule ^sale sale.php [NC]
RewriteRule ^brands/([^/]+) /designer.php?idnr=$1 [NC]
RewriteRule ^product/([^/]+)/([^/]+) /product.php?pid=$1&fsite=$2 [NC]
  • 写回答

1条回答 默认 最新

  • 我在西湖1 2014-03-01 13:26
    关注
    1. Make sure all your R rules are at the top.
    2. RIght after R rules you should have your new rule:

      RewriteRule ^(en|de|fr|ja|ru)/(.*)$  $2?language=$1 [L,QSA]
      
    3. Rest of internal rewrite rules should always end with these flags:

      [L,QSA,NC]
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源