【问题标题】:htaccess redirect 301 (both www and non-www)htaccess 重定向 301(www 和非 www)
【发布时间】:2014-04-09 09:34:06
【问题描述】:

我有两个域:

http://www.domain.comhttp://domain.com 每个都指向同一个目录。现在我有了一个新域 (http://foo.com)

不幸的是,catch all 指令不起作用,因为子目录的名称已更改。我需要大约 20 个单次重定向,例如

/file1.html -> /newdir/
/x.html -> /y/
...

这意味着,http://www.domain.com/dir1http://domain.com/dir1 都应永久重定向到 http://foo.com/newdir1。与其他目录相同。如何通过 htaccess 重定向实现这一目标?

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    将此规则放在domain.com的根.htaccess中:

    RewriteEngine on
    
    ewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^ http://foo.com%{REQUEST_URI} [L,R=301]
    

    【讨论】:

      【解决方案2】:

      试试这个

      Options +FollowSymLinks
      RewriteEngine on
      RewriteRule ^folder1(.*)$ http://www.newdomain.com/$1 [L,R=301]
      

      【讨论】:

      • 对于 20 个文件夹中的每一个?我将如何添加其他规则,只是每个子目录的规则?我想 RewriteEnge on 和 Options... 只运行一次?
      • 我建议为每个文件夹使用一行。
      猜你喜欢
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 1970-01-01
      • 2019-01-29
      • 2019-02-04
      • 2019-08-12
      • 1970-01-01
      相关资源
      最近更新 更多