user1435832
user1435832

Reputation: 1

How do I redirect only URLs 4 folder levels deep but not 3 levels

My site needs to redirect everything with four subfolders to a different subdomain...

domain.com/1/2/3/4 

must not redirect

and

domain.com/1/2/3

must redirect to

newsub.domain.com/1/2/3

Upvotes: 0

Views: 465

Answers (1)

Christopher
Christopher

Reputation: 2057

If you want to redirect domain.com/1/2/3/4 but not domain.com/1/2/3 use this:

RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ http://sub.domain.com/$1/$2/$3/$4 [L]

If you want to redirect domain.com/1/2/3 but not domain.com/1/2/3/4 this should help you:

RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ http://sub.domain.com/$1/$2/$3 [L]

Upvotes: 1

Related Questions