I have an application that requires SSL in a folder called "secure".
So within the "secure" folder of my site in the .htaccess file I'm using the following code to force https:// on that section of the site:
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} secure
RewriteRule ^(.*)$ https://domain.com/secure/$1 [R,L]
How could I modify this so that domain.com/secure/pay/callback would be able to use regular http://
Thank you.
Just add an exclusion
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} secure
RewriteCond %{REQUEST_URI} !/secure/pay/callback
RewriteRule ^(.*)$ https://domain.com/secure/$1 [R,L]
That's a pretty specific case, though; is that enough?
Related
Looking to redirect an entire domain to its https://example.com version for any variants that are requested (http://, https://www., and www.) in the most SEO friendly way possible.
(I am aware that there are a lot of similar Q/A's, but they seem to be specific so I decided to start with a clean post).
I am currently using this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
But I have been told that the redirect is not 301, and it also does not redirect the https://www. version.
Is there a simple way to do this all in one go?
Thank you in advance!
Take care
You can use a single rule in your site root .htaccess for this:
RewriteEngine On
# remove www and turn on https in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
Use a new browser to test the change.
This is what I'm using right now to redirect all traffic to https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I would like to have this configuration but exclude one particular folder. The reason I'm doing this is that I have installed an add-on domain on the current hosting account and while the main domain has an SSL certificate installed, the one that I have recently added doesn't.
Adding the addon domain creates a folder inside the root folder of the primary domains and because I'm redirecting all traffic through the htaccess configuration, it also tries to access the https version of the new addon domain.
You can exclude a folder using a RewriteCond:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/someFolder/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
You need to add a condition into it, so use this instead:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/foldername
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Clear your cache before testing this.
If I read your question correctly, you would like to redirect all traffic that hits your site to https://, except for a single folder, right?
If that's the case, this should work:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/<folder-name>/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Just replace with the name of the folder you want to exclude.
This is driving me bananas. For some reason my domain will not work to redirect https-WWW to https-non-WWW. This works with every other permutation except https://www.nextoronto.com
What code do I use in the .htaccess that will allow it to work for all permutations?
Edit: This is the rewrite code now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.nextoronto\.com [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [L,R=301]
It looks sound, perhaps that rule isn't being reached due to other rules in front of it?
Here is what I use that works:
# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
# My other rewrites for routing all requests to index.php go here...
Edit the URL and try with this code:
RewriteEngine on
rewritecond %{http_host} ^www\.example\.com [nc]
rewriteCond %{SERVER_PORT} 80
rewriterule ^(.*)$ https://example.com/$1 [r=301,nc]
Step 1
You should make .htaccess file like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1
Step 2
Go to the directory, then view mark the option file extension. Then see the .htaccess file.
When no rewrite works, no matter what you do, consider what happened to me. IIS or WAMP, on my laptop, redirected all calls to my domain (call it example.com) to localhost. So creating all the rewrites on my example.com server were to no avail because no calls to example.com ever made it out of my computer. Just do a "ping example.com" and if you get an IP of 127.0.0.1, edit your HOSTS file.
I have a domain: http://example.xoc.uam.mx. I want to require the use of SSL in it (it's a folder of a server). I have this code in the .htaccess but it's not working. What I am doing wrong?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^example\.xoc\.uam\.mx$ [NC]
RewriteRule ^(.*)$ https://example.xoc.uam.mx$1 [R,L]
PS. I already have all the SSL features working, this is, I think, the only thing I miss.
Best Regards.
Your code has some errors. To parse domain name you must use HTTP_HOST instead of REQUEST_URI.
You can replace it by this one
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.xoc\.uam\.mx$ [NC,OR]
RewriteCond %{HTTP_HOST} ^111\.222\.333\.444$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
I have a certain sub-domain which requires an SSL connection for all pages on that subdomain.
This is my current .htaccess script:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
I have a single page on the subdomain which must not have SSL access (causes issues with accessing files on another server without a certificate).
My mod_rewrite knowledge is very limited. I've done a search but can't find what I need.
My question is, the page which must not have https is called 'tutorial.php'. Is there a way to redirect all pages except tutorial.php to https?
I guess in pseudo-code, the RewriteCond would be similar to:
RewriteCond %{SERVER_PORT} 80 AND {WEB_PAGE}!='tutorial.php'
Thanks
Try this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/tutorial\.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTPS} on
RewriteRule ^tutorial\.php$ http://%{HTTP_HOST}/tutorial.php [R,L]