【问题标题】:htaccess redirect when there is a space in urlurl中有空格时htaccess重定向
【发布时间】:2012-09-22 03:36:33
【问题描述】:

我想从仍然出现在谷歌搜索中的旧网址重定向到新网址。旧网址是这样的:

http://www.marionettecolla.org/file%20_mostra_milano/mostra_marionette-milano.htm

我想把它重定向到主页:

http://www.marionettecolla.org/

我在我的 .htaccess 中使用了这个:

Redirect http://marionettecolla.org/file\ _mostra_milano/mostra_marionette-milano.htm http://marionettecolla.org/

但我收到错误 500...有人知道如何解决这个问题吗?

【问题讨论】:

    标签: html .htaccess url redirect web


    【解决方案1】:

    redirectMatch 301 ^/careers[\s]/(.*)$ http://www.soheil.com/careers/$1

    【讨论】:

      【解决方案2】:

      试试这个,即使我们测试过它也有效:

      重定向 301 "/file _mostra_milano/mostra_marionette-milano.htm" http://marionettecolla.orgx/" http://marionettecolla.org

      发布者

      阿拉帕蒂

      【讨论】:

      • 不要使用 301 重定向,它们会缓存在客户端浏览器上,您会失去控制,从而使其永久化。
      【解决方案3】:

      你不能像 "\ " 那样逃避空间。正确的做法是 "\s"

      虽然我不确定在 htaccess 文件中用“\s”代替空格是否可以解决问题。请让我知道它是否有效。

      【讨论】:

      • \s 太宽泛了。它匹配任何空格,而不仅仅是空格。
      【解决方案4】:

      这应该可行:

      Redirect 301 "http://marionettecolla.org/file _mostra_milano/mostra_marionette-milano.htm" http://marionettecolla.org/
      

      把它放在一对双引号" ... "之间

      更新:

      这也是另一种方式,适用于任何类型的空间:

      redirectMatch 301 http://marionettecolla.org/file[\s]_mostra_milano/mostra_marionette-milano.htm http://marionettecolla.org/
      

      【讨论】:

      • Mahsa,看看这个,我在 Redirect 旁边添加了 301 ...它现在应该可以使用了
      • 我已经更新了解决方案……你可以在那里看到[\s]。这一个也应该有效...
      • 如果您使用双引号,那么通常需要通过正则表达式转义的所有其他字符都将变为无效。这是一个副作用很大的解决方案,只适用于狭窄的情况,比如这个。
      • 不要使用 301 重定向,它们会缓存在客户端浏览器上,您会失去控制,从而使其永久化。
      猜你喜欢
      • 2019-06-26
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      相关资源
      最近更新 更多