.htaccess htaccess rewriterule,共8条RewriteRules,可以单独工作,但不能一起工作

.htaccess htaccess rewriterule,共8条RewriteRules,可以单独工作,但不能一起工作,.htaccess,mod-rewrite,https,flags,subdirectory,.htaccess,Mod Rewrite,Https,Flags,Subdirectory,下面是整个htaccess文件 它应该(并且适用于除管理文件夹外的所有内容): 将www.添加到键入的URL(但不是用于管理文件夹,只需将其保留) 从键入的URL中隐藏index.php(但不是用于管理文件夹,只需保留它即可) 根据键入的URL将http替换为https,或将https替换为http(但不适用于管理文件夹,因为管理文件夹应始终为https) 不幸的是,对于下面的.htaccess文件,http://(和https://)www.mydomain.com/administrat

下面是整个htaccess文件

它应该(并且适用于除管理文件夹外的所有内容):

  • 将www.添加到键入的URL(但不是用于管理文件夹,只需将其保留)
  • 从键入的URL中隐藏index.php(但不是用于管理文件夹,只需保留它即可)
  • 根据键入的URL将http替换为https,或将https替换为http(但不适用于管理文件夹,因为管理文件夹应始终为https)
不幸的是,对于下面的.htaccess文件,
http://(和https://)www.mydomain.com/administration/index.php
转到404错误页面。如何修复

因此,.htaccess中的#block0、#block1、#block2工作正常,它们可以正常工作(管理文件夹的URL总是https,没有重定向到404页面)

另外,#block0、#block3-#block8也可以正常工作(对于任何不属于管理文件夹的URL都可以正常工作)

但是,一旦我把它们放在一起(在#block0-#block2之后加上#block3-#block8),然后
http://www.mydomain.com/administartion/index.php
开始转到404页

原因是什么?如何修复? 多谢各位

#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]

更改
[R,L=301]
应该是
[R=301,L]
#block1
#block7
#block8


还要设置一个https证书,并且在apache的
.conf
中是否有
VirtualHost*:443
。非常感谢。虽然没有解决我的问题,但我已经解决了问题,它在另一个.htaccess文件中(删除另一个.htaccess文件,在另一个文件夹中,一切正常)。非常感谢。