Mario Parra
Mario Parra

Reputation: 1554

Rewrite URLs with different domains and similar paths

I need to redirect all URLs formatted as http://www.example.org/dir/subdir/ to http://subdomain.example.org/subdir/. For example, http://www.example.org/dir/subdir/page would redirect to http://subdomain.example.org/subdir/page.

I tried rewrite ^(/dir/subdir.*) http://subdomain.example.org$1 permanent;, but this keeps the /dir/ part, which I want to omit.

Upvotes: 0

Views: 23

Answers (1)

Chang Sheng
Chang Sheng

Reputation: 110

Your rewrite rule is capturing the /dir/ part too. Try this:

location /dir/subdir {
    rewrite ^/dir(.*)$ http://subdomain.example.org$1 permanent;
}

Upvotes: 1

Related Questions