apache - 使用参数重定向 URL
问题描述
我想重定向网址:
prolist.php?id=1297&lang=en
对此:
details.php?id=1297
但是 id 不想重定向在 URL 末尾没有“lang=en”参数的其他 URL。
解决方案
所以你想为你的重定向规则实现一个条件,它与查询字符串匹配一个精确的模式:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(\d+)&lang=en$
RewriteRule ^/?prolist\.php$ /details.php?id=%1 [QSD,R=301]
也许你还想实现一个内部重写规则:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(\d+)&lang=en$
RewriteRule ^/?prolist\.php$ /details.php?id=%1 [QSD,L,R=301]
RewriteCond %{QUERY_STRING} ^id=(\d+)$
RewriteRule ^/?details\.php$ /prolist.php?id=%1&lang=en [L]
推荐阅读
- regex - 正则表达式后视中的可选空格
- r - 在 Rshiny 中绘制某些值
- soap - 如何让wsdl符合soap输入
- python - 没有名为“分类”的模块
- amazon-web-services - 为什么 boto3.client("ecs").describe_tasks(...) 并不总是有 stopCode?
- spartacus-storefront - 错误类型错误:无法读取未定义的属性“__source”
- python - 如何在python中隐藏标题栏或窗口
- javascript - 使用字典在 D3.js 中绘制图形
- python - 在 Selenium Python 中更改页面后查找元素的问题
- regex - 电子邮件的正则表达式,但带有白名单