问题原文
原帖链接 · Michael Purvis · CC BY-SA 4.0
Update 6/26/18: I appreciate that this may be a duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask however, I did mention in my original post that I had been to that post and found the tester site from that post. I did read that post, and while I am still a novice to rewrite rules, I don't think this is duplicate; however I could be wrong.
I am trying to set up a new rewrite rule within my .htaccess file (below)
SetEnv HTTPS on
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA]
Options - Autodiscover
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]
</IfModule>
I found this online tester within this post: Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
Link to the tester: .htaccess tester
When I ran my configuration, I got the following output debugging info for .htaccess
My Question:
- How do I make sure that the index.php is not getting routed wrongly based on the output of the 'debugging info for .htaccess'?
In the output of the 'debugging info for .htaccess', the index.php is getting appended to the autodiscover.xml -- which is NOT what I need to happen. - What is wrong with my configuration that causes it to fail regarding the Autodiscover portion? The 'debugging info for .htaccess' states that the condition was met only because of the 'OR' in my configuration.
Thank you to anyone that see this and offer's any kind of assistance or explanation!! :-)
已采纳解答
原帖链接 · Esa Jokinen · CC BY-SA 4.0
The last rule doesn't have any conditions, so it is used always.
RewriteRule ^.*$ autodiscover.php [NC,L]
The
RewriteConddirective defines a rule condition. One or moreRewriteCondcan precede aRewriteRuledirective. The following rule is then only used if both the current state of the URI matches its pattern, and if these conditions are met.
Therefore, all your conditions are related to the previous rule, instead:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
Also:
You only need
RewriteEngine Ononce.Options- Autodiscoverwould have a syntax error IF there was such a server feature.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
