【问题标题】:How to redirect a directory that not exists to another domain?如何将不存在的目录重定向到另一个域?
【发布时间】:2016-04-08 08:35:43
【问题描述】:

我想在以下条件下从一个站点到另一个站点进行 301 重定向:

例如:
我想重定向
http://domain1.xxx/peterhttp://domain1.xxx/gabriela .. etc..(多个用户)

http://domain2.xxx/mynet/peterhttp://domain2.xxx/mynet/gabriela ...

结构是:
来自http://domain1.xxx/{user}
http://domain2.xxx/mynet/{user}

有问题:domain1.xxx站点为空(peter、gabriela...子目录不存在)

我已经在 domain1.xxx .htaccess 上像这样配置了我的 .htaccess

Redirect 301 / http://domain2.xxx/mynet/

如果文件夹存在,重定向工作,但如果目录不存在,我得到一个禁止响应(例如彼得):

禁止
您无权访问此服务器上的 /peter。

非常感谢

【问题讨论】:

  • 通过 DNS 重定向可能更好?...谢谢

标签: apache .htaccess mod-rewrite redirect dns


【解决方案1】:

改用RedirectMatch

RedirectMatch 302 ^/(\w+)/?$ http://domain2.xxx/mynet/$1

清除浏览器缓存后进行测试。

【讨论】:

  • 你好@anubhava,对不起,这不起作用,我得到了不好的回应..看(responsabl.es)和(responsabl.es/xxx)不起作用,但(responsabl.es/diarioresponsable)正在重定向到@ 987654324@ 并且工作正常(我创建了一个空的 diarioresponsable 文件夹)--- :(
  • 可能我需要尝试使用 PHP 或 DNS 别名...你觉得 @anubhava 怎么样?
  • responsabl.es/diarioresponsable 工作正常,并在我的浏览器中正确重定向到 diarioresponsable.com/redponsable/diarioresponsable
  • 是的,但这是因为我创建了 diarioresponsable 空文件夹。如果您尝试使用另一个随机数:responsabl.es/example 不要重定向到 diarioresponsable.com/redponsable/example...
  • 是的,我的 .htaccess 只有你告诉我的那一行 :) RedirectMatch 302 ^/(\w+)/?$ http://domain2.xxx/mynet/$1
【解决方案2】:

抱歉,这是一个 apache 错误配置!

正确的做法是:

Redirect 301 / http://domain2.xxx/mynet/

谢谢,西罗

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-22
    • 2017-08-26
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多