1

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:

  1. 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.
  2. 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!! :-)

  • In your example (debug info) you've not actually stated what URL is being requested and what the desired output should be. – MrWhite Jun 26 '18 at 00:14
  • Possible 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](https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever) – Jenny D Jun 26 '18 at 07:14

1 Answers1

1

The last rule doesn't have any conditions, so it is used always.

RewriteRule ^.*$ autodiscover.php [NC,L]

The RewriteCond directive defines a rule condition. One or more RewriteCond can precede a RewriteRule directive. 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 On once.

  • Options- Autodiscover would have a syntax error IF there was such a server feature.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • Hi! Thanks for the answer! Basically you are saying that I have to much stuff going on in my .htaccess file, correct? – Michael Purvis Jun 25 '18 at 17:17
  • Yes. Frankly, it looks like copy pasta mix from different sources. – Esa Jokinen Jun 25 '18 at 17:18
  • Thank you! Yes, that is mostly correct. The first part was what we had from the time we built the server. The last half is what I found in the wild and modified for our use case. I'll post up the newly modified .htaccess file soon. – Michael Purvis Jun 25 '18 at 17:32