AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1043748
Accepted
VaNa
VaNa
Asked: 2020-11-25 07:19:27 +0800 CST2020-11-25 07:19:27 +0800 CST 2020-11-25 07:19:27 +0800 CST

Nginx 使用 # 重定向到 URL

  • 772

我希望例如https://example.com/to/redirect被 nginx 重定向到https://example.com/some/url/with/#my-beautiful-id. 但是,在 nginx 配置文件#中用于注释

可能吗?我应该向 nginx 配置写入什么内容才能正常工作?

不工作

server {
    ...
    location /to/redirect {
        ...
        return https://example.com/some/url/with/%23my-beautiful-id;
    }
}
url nginx
  • 1 1 个回答
  • 509 Views

1 个回答

  • Voted
  1. Best Answer
    Ivan Shatsky
    2020-11-26T00:42:24+08:002020-11-26T00:42:24+08:00

    该#字符不会作为注释的开头处理为某个字符串的一部分,例如https://example.com/some/url/with/#my-beautiful-id. 但是,它作为注释的开头处理,前面带有空格、{或}字符;(不确定这是一个完整列表)。为了防止以这种方式处理它,您需要引用您的字符串:

    set $test 123#456;     # $test variable value is '123#456'
    set $test 123;#456;    # $test variable value is '123', #456 treated as the comment
    set $test "123;#456";  # $test variable value is '123;#456'
    set $test '123;#456';  # $test variable value is '123;#456'
    

    通常不需要在 nginx 配置中引用字符串(除非它包含空格或其他一些特殊字符{,例如}等),但你总是可以自由地这样做,这意味着行

    return https://example.com/some/url/with/#my-beautiful-id;
    

    和

    return "https://example.com/some/url/with/#my-beautiful-id";
    

    完全相等。

    • 1

相关问题

  • Sane Sharepoint 2007 网址

  • IIS 7 中的 URL 重写

  • 为什么有些网站的网址中没有“www”就无法显示?[关闭]

  • 如何将 URL 添加到 wiki (MediaWiki) 支持的文档?

  • 如何强制我的网址始终以 www 开头?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve