Force a Directory to load in HTTPS SSL

Use the following .htaccess code to force a particular directory to load in HTTPS/SSL mode.

# Force SSL over mydirectory
RewriteEngine On
# file.php will not be forced over SSL - Uncomment the line below if needed
#RewriteCond %{REQUEST_URI} !^/mydirectory/file.php [NC]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^mydirectory(/.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Was this answer helpful?

Also Read

Speed up WordPress Leveraging Browser Caching via .htaccess

Insert the following code to your .htaccess file to increase the speed of your WordPress website...

.htaccess RewriteRule Examples

Here are some useful mod_rewrite RewriteRule redirect examples that you can use in your .htaccess...

.htaccess URL Masking Examples

If you would like to access a specific URL for your domain but do not display it in the browser's...

.htaccess 301 Redirect Generator

A simple .htaccess 301 redirect generator to be used to create SEO friendly permanent redirects....

.htaccess rules to Harden your website’s Security

Below you see a list of the important rules that you can add to your .htaccess file to harden...