【问题标题】:Apache - Redirect 301 pdf to pdf with spaces ( binary file )Apache - 将 301 pdf 重定向到带空格的 pdf(二进制文件)
【发布时间】:2010-12-04 01:42:35
【问题描述】:

我想要什么:

到 301 重定向 /file_new.pdf 到 /file new.pdf ( %20 之间的空格 文件和新)

我知道:

  • 我可以依靠使用 mod_rewrite 的 RewriteRule 301,使用此线程中的解决方案:@mod_rewrite with spaces in the urls
  • 我可以将文件重命名为不包含空格并将其替换为破折号/下划线

但是,我个人很好奇如何做到这一点。到目前为止,这是我所拥有的:

Redirect 301 /file_new.pdf http://sitename.com/file\ new.pdf

当我调用 configtest 时,conf 文件解析器抛出错误:

重定向需要两个或三个参数, 一个可选的状态,然后记录到 被重定向和目标网址

编辑: 显然 mod_rewrite 或 Redirect 301 方法对我有用,可能是因为无论出于何种原因,它们都没有应用,因为文件实际上存在于该位置。

<VirtualHost *:80>
DocumentRoot /www/sitename_com
ServerName site.local
Options -MultiViews

RewriteEngine on
Redirect 301 /pdf/file_new.pdf http://site.local/pdf/file%20new.pdf
RewriteRule ^/pdf/file_new.pdf http://site.local/pdf/file\ new.pdf
RewriteLog "/www/rewrite.log"
</VirtualHost>

在 rewrite.log 中,它尝试将模式与每个相应的 uri / http 请求进行匹配。我认为在它到达 mod_alias/mod_rewrite 的东西之前,有些东西正在控制。

总而言之,它直接转到浏览器中的 file_new.pdf 而不是 301。我很肯定 aliasrewrite 已启用。我的 apache 版本是 2.2。

【问题讨论】:

标签: apache mod-rewrite http-status-code-301 mod-alias


【解决方案1】:

Redirect 实际上是 mod_alias 的一部分,而不是 mod_rewrite。我很高兴 %20 有效,您还可以使用引号告诉 apache 包含空格的路径是要重定向到的 URL,而不是两个单独的项目:

Redirect 301 /pdf/file_new.pdf "http://site.local/pdf/file new.pdf"

【讨论】:

  • 我知道Redirectmod_alias 的一部分,因为我最初将它标记为mod-alias,它实际上无论出于何种原因都不起作用,也许是我的虚拟主机中的某些东西?我并没有对默认的 httpd.conf 进行太多修改,这是在一个新的 Lenny debian 盒子上。我会试试你的方法,看看是否有效。
猜你喜欢
  • 2012-09-04
  • 2014-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多