Below is the whole htaccess file.
It should (and works fine for everything except administration folder):
- add www. to the URL typed (but not for administration folder, just leave it),
- hide index.php from the URL typed (but not for administration folder, just leave it),
- replace http with https, or https with http depending on the URL typed (but not for administration folder, because administration folder should always be https)
Unfortunately, with the .htaccess file below, both http:// (and https://) www.mydomain.com/administartion/index.php go to 404 error page. How to fix?
So, #block0, #block1, #block2 in .htaccess work fine, they make their work (URLs to administration folder are always https, no redirections to 404 page)
Also, #block0, #block3 – #block8 make their work (works fine for any URLs that is not to administration folder)
But, once I put them all together (add #block3 – #block8 right after #block0-#block2), then http://www.mydomain.com/administartion/index.php starts going to 404 page.
What’s the reason and how to fix?
Thank you.
#block0
RewriteEngine On
#block1
#special rules for administration folder, http to https, if http
RewriteCond %{REQUEST_URI} ^/administration
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
#block2
RewriteCond %{REQUEST_URI} ^/administration
RewriteRule ^administration - [NC,L]
#URLs to administration folder should be stopped before this line.
#block3
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
#block4
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^index.php / [L,R=301]
#block5
#if its a resource (add others that are missing)
RewriteCond %{REQUEST_URI} \.(gif|css|png|js|jpe?g)$ [NC]
#do nothing
RewriteRule ^ - [L]
#block6
#determine if page is supposed to be http
RewriteCond %{QUERY_STRING} (^|&)(p=home1?|qqq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]
#block7
#all pages that are supposed to be http redirected if https
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} on
RewriteCond %{ENV:IS_HTTP} 1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
#block8
#all other pages are sent to https if not already so
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteCond %{ENV:IS_HTTP} !1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
change
[R,L=301]should be[R=301,L]in#block1#block7#block8Also setup a certificate to
httpsand do you have aVirtualHost *:443in your.confof apache?