I need to change this so that one file in wp-admin is not forced through https:

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ https://%{SERVER_NAME}/$1/ [R=301,L]

This forces all requests to /wp-admin through SSL but it is breaking a wordpress plugin which needs to access wp-admin/admin-ajax.php.

Is there a way to adjust the rule so that it will allow non encrypted requests to that one file?


3 Answers 3


This forces all requests to /wp-admin through SSL...

Actually, no it's not. As the code-comment states, it simply "adds a trailing slash to /wp-admin". It only targets URLs that end in /wp-admin, so it already excludes the URL wp-admin/admin-ajax.php. There is nothing more you need to do to these directives.

If wp-admin/admin-ajax.php is being forced to HTTPS then something else is doing that (possibly even WordPress itself).

RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ https://%{SERVER_NAME}/$1/ [R=301,L]

Aside: The RewriteCond directive is not required here. This could arguably be simplified with just a single directive (which would also be more efficient):

 RewriteRule ^(.+/)?wp-admin$ https://%{SERVER_NAME}%{REQUEST_URI}/ [R=301,L]

Add an additional condition before your rule that does the redirect to https:

RewriteCond %{REQUEST_URI} !=/wp-admin/admin-ajax.php

Which will prevent the rewrite/redirect from occuring for this file

  • The current rule already has a condition that matches a specific URL, so this URL is already excluded! (Both can't be true.)
    – MrWhite
    Jul 1, 2019 at 22:52

Have not tested it, but this should do it...

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
Redirect /directory/file.html http://domain.com/directory/file.html
  • thats for a folder. Will it work for a specific file URL? ALso, wouln't it be RewriteCond %{REQUEST_URI} ^.*/somefolder$ ?
    – codecowboy
    Nov 2, 2010 at 15:24
  • @codecowboy - Sorry, I was under the understanding you wanted it done for the entire directory. I have modified my answer.
    – Jeremy
    Nov 2, 2010 at 15:47
  • Redirect is part of mod_alias, not mod_rewrite. However, even if you change this to use RewriteRule, it will still result in a redirect loop.
    – MrWhite
    Jul 1, 2019 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.