代码之家  ›  专栏  ›  技术社区  ›  Steven Smethurst

.htaccess重定向到包含空格的url

  •  12
  • Steven Smethurst  · 技术社区  · 14 年前

    http://example.com/one two three.exe

    正确的URL是 http://example.com/one_two_three.exe

    注意下划线而不是空格。

    我在网上搜索了一下,找到了这个.htaccess的代码片段

    # Redirect old file path to new file path
    Redirect /one%20two%20three.exe http://example.com/one_two_three.exe
    

    我将此代码段添加到文件顶部先前存在的root.htaccess中。
    但它似乎不起作用。我的浏览器没有重定向,我得到一个404错误页。

    我相信这与原始URL中的空格有关,但我不知道如何处理URL中的空格。

    建议?

    1 回复  |  直到 7 年前
        1
  •  34
  •   TylerH Ash Burlaczenko    7 年前

    你可以尝试一些东西(都没有经过测试)

    Redirect "/one two three.exe" http://example.com/one_two_three.exe
    

    或使用 RewriteRule Redirect :

    RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe