【问题标题】:Remove # from URL in nginx从 nginx 中的 URL 中删除 #
【发布时间】:2016-01-14 14:36:55
【问题描述】:

我正在从旧站点 URL 重定向。一组链接特别用于视频播放器的开始和停止时间。

http://foo.com/index.php?option=com_tvwplayer&eventID=2015020086#start=3263&stop=5621

我可以通过使用这个来很好地重定向基础:

if ($option ~ com_tvwplayer){
   set $eventID $arg_eventID;
   set $args '';
   set $nArg '?customID=';
   rewrite ^.*$ $uri/watch/$nArg$eventID  permanent;
}

这适用于:

http://foo.com/index.php?option=com_tvwplayer&eventID=2015020086

改成:

http://foo.com/watch/?customID=2015020086

但是 URL 中时间指示符的 # 需要删除或替换为 & 才能使其看起来像这样:

http://foo.com/watch/?customID=2015020086&start=3263&stop=5621

有什么想法或花哨的正则表达式可以让它工作吗?

【问题讨论】:

  • 您不能这样做,因为浏览器不会将 URL 的 #... 部分发送到服务器。
  • 您是否尝试在 javascript 的前端执行此操作?你能提供更多的背景信息吗?

标签: regex nginx rewrite


【解决方案1】:

你可以试试sed:

URL="http://foo.com/index.php?option=com_tvwplayer&eventID=2015020086#start=3263&stop=5621"
NEW_URL=`echo $URL | sed 's/#/&/g'`
echo $NEW_URL

此代码将包含有问题的 # 的 URL 通过管道传输到 sed 中,该 sed 会查找所有 # 并将其替换为 & 并将其保存到名为 NEW_URL 的新变量中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 2016-07-22
    • 2015-05-13
    • 2020-02-20
    • 2021-02-02
    • 1970-01-01
    • 2019-09-15
    相关资源
    最近更新 更多