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 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题