regex - 重定向到锚点
问题描述
我需要将这样的 url 重定向domain.tld/instagram/anchor
到domain.tld/instagram/#anchor
.
这应该只发生在与 instagram 路径的链接上,并且必须通过 .htaccess 处理,我试过这个,现在我被卡住了,因为它什么都不做:
RewriteRule ^/instagram/(\d[^/]+) /instagram/#$1/ [R=301,NE,L]
解决方案
对于您显示的示例,请尝试以下规则。请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteRule ^instagram/([^/]*)/?$ /instagram/#$1/ [R=301,NC,NE,L]
要点:
- 始终在规则中使用 NE 和 NC 标志,以确保条件格式正确。
- 您不需要在您的正则表达式中使用 \d ,因为您显示的示例中没有数字。
- 您需要确保将此规则保持在顶部,因为它应该首先出现重定向,以防以后我们有其他与之相关的规则。
- 你不需要匹配
/
从这里开始。
推荐阅读
- reactive-programming - 使用动态查询在 ReactiveMongoRepository 上实现分页和排序
- apache - CNAME 到另一个子域
- c# - 从 c# 中的 html 获取实际的 href 值
- ios - 如何支持现有 Swift 应用 iOS 的暗模式支持?
- pdf - 生成 ToUnicode CMap(以编程方式或可视方式)
- python-3.7 - 阅读之间
MDF文件中的标签? - python - python中带有动态if语句的for循环
- mysql - Mysql在不同的行和不同的列中选择相同的值
- sql - 左连接中的重复行
- ios - 尝试将日期格式化程序类型(从时间选择器)转换为整数