Rayyan Riaz
Rayyan Riaz

Reputation: 97

.htaccess redirect to subfolder, not working perfectly

I have written a simple redirect condition as:

RewriteCond %{HTTP_HOST} !^my-domain\.com$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]

It redirects correctly from www.mysite.com to mysite.com/hu/

But it does not redirect mysite.com to mysite.com/hu/

Please help

Upvotes: 0

Views: 101

Answers (1)

zessx
zessx

Reputation: 68790

You've cleary copied this code without understanding it. This is a typical htaccess to remove the www. part of a domain.

To redirect your homepage to a subfolder, use this code instead :

RewriteCond %{HTTP_HOST} ^(www\.)?my-domain\.com$
RewriteCond %{REQUEST_URI} !^hu/$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]

Upvotes: 2

Related Questions