Report this

What is the reason for this report?

Redirect .htaccess only when no subdomain

Posted on March 8, 2020

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]

Thanks.



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!

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 .* 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.

Regards, KDSys

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.