Max Smith
Max Smith

Reputation: 9

How can I redirect everything in one sub directory using htaccess

I have a website and need everything in my subdomain to redirect to my home page.

For example I would need www.website.com/sub to redirect back to www.website.com

same with anything else within /sub

so www.website.com/sub/sdjdj/sdsd/dsd ....would also need to redirect to www.website.com

How can I achieve this with htaccess?

Upvotes: 0

Views: 29

Answers (2)

Panama Jack
Panama Jack

Reputation: 24448

You can use this in your .htaccess in the root.

RewriteEngine On
RewriteRule ^sub(?:$|/.*) / [R=302,L]

When you are sure the rule is working as intended, change to 301 in rule.

Upvotes: 1

Croises
Croises

Reputation: 18671

You can use:

RewriteEngine on 
RewriteRule ^sub(?:/|$) / [NC,R,L]

Upvotes: 1

Related Questions