How to 301 redirect an entire domain while preserving the path

后端 未结 3 1653
臣服心动
臣服心动 2020-12-10 01:39

I am redirecting one domain to another, but I want to preserve the path in the redirect. So for example, I want to visit www.example.com/services/education/page.html

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 01:58

    try adding the following to your .htaccess in the root of your example.com domain

    RewriteEngine On
    RewriteBase /
    
    #for all requests to www.example.com
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    #redirect them to new-example
    RewriteRule (.*) http://www.new-example.com/$1 [R=301,L]
    

提交回复
热议问题