.htaccess 301 redirect path and all child-paths

后端 未结 2 1848
温柔的废话
温柔的废话 2020-12-18 15:02

I want accesses to e.g. www.thisdomain.com/docs/path1/path2 to redirect to www.thatdomain.com/path1/path2

(Note that docs is not a part of the new path)

I ha

2条回答
  •  一向
    一向 (楼主)
    2020-12-18 15:34

    According to section "Redirect Old domain to New domain using htaccess redirect" of the first Google result which I found searching for "htaccess redirect" (without the double quotes), this piece of code will suffice:

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

    According to their description of the technique, it will redirect the directory the .htaccess file is placed in recursively (including any child paths), just as you intend. Of course, mod_rewrite needs to be present for the rewrite directives to work.

提交回复
热议问题