Redirect .htaccess only when no subdomain

Hello. I have a .htaccess who redirect all request do the /public/ directory. But i want only redirect when no subdomain… Actual .htaccess :

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @Simsimpicpic,

You can use something like the following

RewriteCond %{HTTP_HOST} !^static1\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^static2\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^static3\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} (\.|^)example\.com [NC]
RewriteRule .* [R=301,L]

You’ll need to change the static1/2/3 with your actual subdomain and the with your domain.

Regards, KDSys