【问题标题】:.htaccess Redirect on a url with spaces in it.htaccess 在带有空格的 url 上重定向
【发布时间】:2011-03-31 16:48:53
【问题描述】:

我有一个来自另一个网站的链接,我无法控制 http://example.com/one two three.exe

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

注意下划线而不是空格。

我在网上搜索,发现这个代码 sn-p for .htaccess

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

我将此 sn-p 添加到文件顶部的预先存在的根 .htaccess 中。
但这似乎不起作用。我的浏览器没有重定向,我得到一个 404 错误页面。

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

建议?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    你可以尝试几件事(都未经测试)

    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
    

    【讨论】:

    • 第二个为我工作。我需要重定向到一个带有空格的 URL “\” 完美!
    猜你喜欢
    • 2019-06-26
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 2022-07-01
    相关资源
    最近更新 更多