.htaccess 301 redirect all pages on old domain to a single page on new domain

前端 未结 3 504
日久生厌
日久生厌 2020-12-07 03:07

I\'m looking to redirect each and every page on the old domain to a single page on the new domain. It should also redirect both the www and

3条回答
  •  Happy的楠姐
    2020-12-07 03:33

    This has already been answered, but here's the code altogether containing helpful comments so people have a reference to look back on later should they forget what it does.

    Put this in your .htaccess file:

    ## Each and every page on old domain redirects to single page
    ## By appending question mark to new domain, query strings are removed
    RewriteEngine on
    RewriteCond %{HTTP_HOST} old\.com$
    RewriteRule .* http://www.new.com/? [L,R=301]
    

    You can also redirect to a sub directory on another domain, as was the case that I needed to do like this:

    ## Each and every page on old domain redirects to single page
    ## By appending question mark to new domain, query strings are removed
    RewriteEngine on
    RewriteCond %{HTTP_HOST} old\.com$
    RewriteRule .* http://www.new.com/sub-directory/? [L,R=301]
    

提交回复
热议问题