Home htaccess, https, and www
Reply: 0

htaccess, https, and www

snjagr Published in 2018-01-10 04:59:26Z

So using htaccess file I want to kick all requests to the non-www url, and rewrite all requests to example.com to example.com/subFolder I'll choose which pages to be https later..

what i have in /.htaccess so far mostly works:

RewriteEngine On
## rewrite base:
#RewriteBase /subFolder

## redirect all? to non-www site: -----------------------
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

## base website url redirect to /subFolder ---------------
#-RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/
RewriteRule ^$ http%{ENV:protossl}://%{HTTP_HOST}/subFolder/ [L]
RewriteRule ^(/)?$ subFolder/ [L] 

## Rewrite non-file/directory URL's -----------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/subFolder/
RewriteRule ^(.*)$ /subFolder/$1 [L]

And in /subFolder/.htaccess:

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

RewriteBase /subFolder

Results are:

On http:
√ non-www => non-www
√ www => non-www
√ subFolder is always hidden in url

On https:
√ non-www => non-www
X www => Redirected to htp://non-www
√ subFolder is always hidden

Everything works as desired except for https requests that include www .

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304539 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO