regex - .htaccess 重定向错误,查询字符串更改
问题描述
我有一个网址是:
http://example.com?country=uk&animal=dog&size=large
我希望将查询字符串更改为
http://example.com?country=uk&animal=cat&size=small
我已经在 .htaccess 测试仪中尝试过这个
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*[&?]|)animal=(dog)&size=(large)([&?].*|)$
RewriteRule ^(.*)$ $1?%1animal=cat&size=small[R=301,NC,L]
但是重写中的 & 不断显示为686
!
http://example.com?country=uk&animal=cat686size=small
任何想法将不胜感激。
解决方案
使用您显示的示例,请尝试遵循 htaccess 规则。请确保在测试您的 URL 之前清除您的浏览器缓存。
##making engine one here.
RewriteEngine ON
##External redirect rule goes here. Please make sure to use correct back references to be used later on.
RewriteCond %{THE_REQUEST} \s/([^?]*)\?(country=)uk&(animal=)dog(&size=)large [NC]
##Applying redirection with 301 redirect here.
RewriteRule ^ /%1?%2uk&%3cat&%4small [R=301,L]
推荐阅读
- go - Go get 没有为 sum.golang.org 使用 GOPROXY
- flutter - 这两种类型的参数有什么区别?
- android - 如何让已经打开的相机在 Android 中添加手电筒?
- java - 如何在 Android 8/9 上为 HttpURLConnection 启用 TLSv1.3?
- adonis.js - AdonisJs 配置指示性
- sql - 如何避免 Sql 中的除法返回 0 或 NULL
- systemd - 以 $SUDO_USER 作为用户启动 systemd 系统服务
- python - pygame中取消跳跃机制的故障
- android - ReactNative Android 应用程序崩溃。更新类型阴影节点中的属性填充时出错:RCTView
- reactjs - 反应 Mapbox 层未显示