htaccess force ssl except for rss feeds - wordpress

My site currently forces SSL everywhere. This is the way that I want except that it is causing issues with my RSS driven newsletter and feedburner. Due to this I need to make exceptions for my feeds.
Can someone help with the proper htaccess rules to pull this off?
My feeds are
/feed
/shop/feed
/forum/discussions/feed.rss
Here is my condition for forcing SSL. This works except that all RSS feeds are forced to.
# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/forum [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]
I tried the following but it did not seem to work correctly.
# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/forum [OR]
RewriteCond %{REQUEST_URI} !^/feed [OR]
RewriteCond %{REQUEST_URI} !^/shop/forum [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]
Your help is greatly appreciated!
Update: This is my current .htaccess file in the root of my server. This is currently redirecting http://photoboothowners.com/feed to https://photoboothowners.com (notice it is dropping the feed directory).
RewriteEngine on
# Use PHP5CGI as default
AddHandler fcgid-script .php
RewriteCond %{HTTP_HOST} ^buyaphotobooth\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.buyaphotobooth\.net$
RewriteRule ^/?$ "https\:\/\/photoboothowners\.com\/starting\-a\-photo\-booth\-business\-build\-or\-buy" [R=301,L]
RewriteCond %{HTTP_HOST} ^photoboothforums\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.photoboothforums\.com$
RewriteRule ^/?$ "https\:\/\/photoboothowners\.com\/forum" [R=301,L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/forum [NC]
RewriteCond %{REQUEST_URI} !feed [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]
RewriteCond %{HTTP_HOST} ^photoboothowners\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.photoboothowners\.com$
RewriteRule ^how\-to\-use\-our\-premium\-print\-designs\-in\-breeze\-dslr\-remote\-pro\/?(.*)$ "https\:\/\/photoboothowners\.com\/how\-to\-use\-our\-photo\-booth\-template\-designs\-in\-breeze\-dslr\-remote\-pro$1" [R=301,L]
RewriteOptions inherit
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^shop\/photo\-booth\-layouts\-and\-samples\.html$ "https\:\/\/photoboothowners\.com\/shop" [R=301,L]
<Files 403.shtml>
order allow,deny
allow from all
</Files>

Your rules are using OR so they read as:
if server port is 80 and the request is not forum OR it is not feed OR it is not shop/forum
That's going to match everything. Get rid of both of the [OR] so that the match reads:
if server port is 80 and the request is not forum AND it is not feed AND it is not shop/forum
EDIT:
Per your updated question, the following line is missing a slash:
RewriteCond %{REQUEST_URI} !feed [NC]
should be
RewriteCond %{REQUEST_URI} !/feed [NC]

Related

How to remove a redirect in .htaccess

I need to build a website for someone, but it is currently redirecting to an appointment booking software. I checked the .htaccess file and there is some sort of redirect code, not sure how to remove it. I tried replacing the entire .htaccess file with a blank one, and every page on the site said "Page not found". Any suggestions? This is what is currently in the .htaccess file.
RewriteOptions inherit
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^suitezen\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.suitezen\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.massagebook\.com\/Bowling_Green\~Massage\~IBTsuitezenmedicalspa$1" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.massagebook\.com\/Bowling_Green\~Massage\~IBTsuitezenmedicalspa$1" [R=301,L]
Any line with a RewriteRule and the [R] flag (in your case written as [R=302 for a temporary redirect and [R=301 for a permanent redirect) is a rewrite rule that tells apache to redirect to the given url. The RewriteCond lines before the rule modify when the RewriteRule after it is executed. In your case you have two redirect rules:
RewriteCond %{HTTP_HOST} ^suitezen\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.suitezen\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.massagebook\.com\/Bowling_Green\~Massage\~IBTsuitezenmedicalspa$1" [R=302,L]
and
RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.massagebook\.com\/Bowling_Green\~Massage\~IBTsuitezenmedicalspa$1" [R=301,L]
Delete those and delete the cache of your browser to see Wordpress again. I see that there are some conditions related to cpanel that are not usually part of a Wordpress installation (see the official wordpress site for an example of the default .htaccess). If for some reason the redirects get re-added to your .htaccess, dive into cpanel to see if there is a configuration option there.

HTTP to HTTPS - Too many redirects

I have a site with Wordpress. I need some single page to redirect HTTPS
I get code form stackoverflow and put in .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /online-order-auto [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/online-order-auto [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.swtest\.ru$
RewriteRule ^(.*)$ http://www.site.ru/$1 [L,R=301]
The browser wrote "ERR_TOO_MANY_REDIRECTS".
I cant understand whats a problem
Try this. I've been looking all over and this is the only way I could make it work...
#non-www. http to www. https
RewriteCond %{ENV:HTTPS} !on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
#non-www. https to www. https
RewriteCond %{ENV:HTTPS} on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]

htaccess rewrite doesn't work after installing WordPress

I've recently installed WordPress. Since I want it running from the root directory and like some nice looking permalinks i've added a new section to my htaccess file on the httpdocs of my server.
Since this time the redirect for other domains isn't working anymore.
This is the current code:
Options +FollowSymLinks
RewriteEngine On
#Redirect to other DOMAINS
#----------------
RewriteCond %{HTTP_HOST} (www\.)?example1.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/e1/.*$
RewriteRule ^(.*)$ /e1/$1
RewriteCond %{HTTP_HOST} (www\.)?example2.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/SR/.*$
RewriteRule ^(.*)$ /SR/$1
#ALTERNATE DOMAINS
# ---------------
RewriteCond %{HTTP_HOST} ^www.gw.nl$ [NC,OR]
RewriteCond %{HTTP_HOST} ^gw.nl$ [NC]
RewriteRule (.*) http://www.gw.info/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.cb.nl$ [NC,OR]
RewriteCond %{HTTP_HOST} ^cb.nl$ [NC]
RewriteRule (.*) http://www.gw.info/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
The WordPress site works as it should. Alternate domains works as well. However, the other two sites are totally out of the running, now displaying the main wordpress website.
If I change RewriteRule . /wordpress/index.php [L] to RewriteRule . /index.php [L] it will return an internal server error.
Anybody got a clue what's the mistake?
adding the flags
[R=301,L]
to the first two rules worked!

Redirect one Wordpress page from HTTPS to HTTP

I have checked all of the related questions I can find in here (and in Google in general), and tried all of the various solutions given, but haven't been able to get this to work.
I am working on a Wordpress site that has recently gone SSL. I have set it up so that all pages are forced to https by adjusting the Settings page in the Admin area, adding the appropriate line to the wp-config file to force the admin side to be https and have modified my htaccess files to the following:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^branding/ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Here's what I would like this to do...
1) http://www.example.com/ (and any sub pages except branding) gets redirected to https://example.com
2) http://example.com/branding stays as it is
3) https://example.com/branding is redirected to http://example.com/branding
The above htaccess code works to force the http: to https:, however, if I enter either http://example.com/branding or https://example.com/branding I am redirected to https://example.com.
I have used numerous variations of the initial Rewrite code and placed it in various places (as instructed in various other answers to similar questions here) with no change to the result.
If anyone can tell me where my error is and how to fix it, it would be much appreciated.
Try this:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^branding(.*) http://%{HTTP_HOST}/branding$1 [R=301,L]
With the help of a colleague, we got it worked out. Here's the updated code...
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The WP-specific rules in the htaccess file cause some strange situations to occur. The main one being that there is an internal rewrite from /branding/ to /index.php, and then WP handles the request within the PHP. The file checks will handle the check to ensure that the index.php file exists. WP will internally deal with redirecting valid page requests that don't have trailing slashes.
Been searching for this for hours... Here is the tweak if you need to redirect more than one page to http from https.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Allow stylesheet in rewrite engine

I have a temporary coming soon page while i test our new website. i have setup an redirect in the .htaccess file using the below code. Problem is that it doesn't get the stylesheet. Any help appreciated, thanks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^7\.150\.99\.110
RewriteCond %{REMOTE_ADDR} !^82\.31\.116\.41
RewriteCond %{REMOTE_ADDR} !^localhost
RewriteCond %{REQUEST_URI} !/coming-soon.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /coming-soon.php [R=302,L]
</IfModule>
Add .css and .js in excluded list:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^7\.150\.99\.110
RewriteCond %{REMOTE_ADDR} !^82\.31\.116\.41
RewriteCond %{REMOTE_ADDR} !^localhost
RewriteCond %{REQUEST_URI} !/coming-soon.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js) [NC]
RewriteRule ^ /coming-soon.php [R=302,L]

Resources