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]


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.

1 answer

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 .* http://www.example.com/public [R=301,L]

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


Submit an Answer