RewriteCond blank domain to the domain with the correct path

58 views Asked by At

How do I set redirects with following conditions:

Url http://domainname.be becomes http://www.domainname.be/nl/

Url http://www.domainname.be becomes http://www.domainname.be/nl/

Url http://domainname.be/nl/custompage/ becomes http://www.domainname.be/nl/custompage/

?

Rewrite conditions

RewriteCond %{HTTP_HOST} ^domainname.be [NC]
RedirectRule ^(.*)$ http://www.domainname.be$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^domainname.be [NC]
RewriteCond %{REQUEST_URI} ^/$
RedirectRule ^(.*)$ http://www.domainname.be/nl$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domainname.be [NC]
RewriteCond %{REQUEST_URI} ^/$
RedirectRule ^(.*)$ http://www.domainname.be/nl$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/nl/custompage /Custompage.aspx?lang=nl [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/nl/custompage/ /Custompage.aspx?lang=nl [L,NC]

But is doesn't work. Also, do you need to clear the browsercache in order to have the latest conditions?

1

There are 1 answers

7
anubhava On

Remove all of your existing rules and use this:

RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.be$ [NC]
RedirectRule ^((?!nl/).*)$ http://www.domainname.be/nl/$1 [R=301,L]

And yes test it out in a different browser to avoid 301 caching issues.