Search code examples
.htaccesshttp-redirecthttpssubdirectoryno-www

Redirect domain.com/folder with www to non-www and at the same time http to https


I have installed into a sub-folder of my domain a Web App. Example: domain.com/webapp

I want to use the Web App with SSL enabled: https://domain.com/webapp

I want to redirect at same time: WWW to NON-WWW and HTTP to HTTPS only for the sub-folder "webapp".

Trying with the code fund in this website didn't actually work 100%, having issues with to many redirects, or redirecting me to the site root not subfolder, etc.

Thanks for your help.


Solution

  • Inside /webapp/.htaccess use this rule:

    RewriteEngine On
    
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://domain.com/%{REQUEST_URI} [R=301,L,NE]