Mod_rewrite working on http but not https - apache

I have a mod_rewrite that works fine on http, but not on https.
Some answers on stack overflow to similar questions suggest adding RewriteBase /, but I already have that.
I'm hosted on godaddy on a shared server. I have contacted godaddy 3 times and they say they can't do anything.
Here is an example of the rewrite:
URL Without Rewrite:
https://www.funded.today/stats/?p=bloodstained-ritual-of-the-night
Mod_Rewrite URL:
https://www.funded.today/stats/iga/bloodstained-ritual-of-the-night
My htaccess file is the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?funded\.today$ [NC]
RewriteRule ^$ https://www.funded.today/%{REQUEST_URI} [R,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stats/(.*)/(.*)$ /stats/?p=$2 [P,QSA]
# BEGIN s2Member GZIP exclusions
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (^|\?|&)s2member_file_download\=.+ [OR]
RewriteCond %{QUERY_STRING} (^|\?|&)no-gzip\=1
RewriteRule .* - [E=no-gzip:1]
</IfModule>
# END s2Member GZIP exclusions
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.*)/(.*)$ - [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help or ideas on this is greatly appreciated!

Related

Use .htaccess to rewrite address from xxx.example.com to example.com/xxx/

I am looking for a way so that users can access their page by typing xxx.example.com and are then forwarded to their respective WordPress post.
Now I already have two rewrite functions on my site: (not written by me)
To use https everywhere:
#Rewrite everything to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
And the WordPress:
# 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
Now, that WordPress function seems to translate example.com/post_title to the corresponding post.
But how do I rewrite it so it translates post_title.example.com to the corresponding post?
And if possible, still showing the xxx.example.com instead of example.com/xxx
The following should work, change your .htaccess to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Rewrite to https
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
# This rewrite rule will only be used if
# we have an empty query string and the http host does not start with www
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^$ http://%{HTTP_HOST}/%1 [L]
# The default wordpress rewrite rule
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
For this to work I guess you need to setup a correct permalink structure in your wordpress installation:

Non-www RewriteRule not working on request URI

I need a website to have all URLs NOT have www in front of it. For this, I have found some useful bits of code here that have helped me out a lot. However, nowhere can I find how to properly do it for ALL request URIs. Currently it only works on the domains homepage.
# 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]
RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC]
RewriteRule ^(.*)$ https://domain.nl%{REQUEST_URI} [L,R=301]
</IfModule>
# END WordPress
Right now www.domain.nl gets rewritten into domain.nl. However, any other like www.domain.nl/anything_else do not get rewritten (also tried adding a / before the %{REQUEST_URI}, did not work).
Any help is appreciated!
With www rule before:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC]
RewriteRule ^ https://domain.nl%{REQUEST_URI} [NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

301 redirect with query parameters isn't working in .htaccess

I have a new website recently uploaded on a domain name and I want to redirect individually all my previous pages to the new ones. (they aren't more than 20)
WHat i've tried to accomplish is the following, but for some reason it isn't working:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^id=16&page=PRICES_SKI_PACKS$
RewriteRule ^(.*)$ http://www.skibansko.bg/prices-ski-packs/ [L,R=301]
Old url: http://skibansko.bg/index.php?id=16&page=PRICES_SKI_PACKS
New url: http://www.skibansko.bg/prices-ski-packs/
It simply is redirecting me to the home page of the new website.
The old website was not on Wordpress and the new one is on Wordpress
The old and the new websites were on the same domain as you can see from the url's.
Probably the WordPress rewriting rules are causing it, you can check them here:
# 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
And my whole .htaccess looks like this:
# 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
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^id=16&page=PRICES_SKI_PACKS$
RewriteRule ^(.*)$ http://www.skibansko.bg/prices-ski-packs/ [L,R=301]
Thank you all in advance!

htaccess 301 redirect to different domain

Trust me, I've searched all over for a solution to my problem, so I don't believe this is a duplicate question.
I need to do the following:
301 Redirect blog.example.com to blog.newexample.com.
What I have is close to working. When I go to the homepage of blog.example.com it will redirect perfectly to blog.newexample.com. However, if I go to blog.example.com/directory/page it does not direct me to blog.newexample.com/directory/page.
Here is what my .htaccess looks like:
# 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]
RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301]
</IfModule>
# END WordPress
I'm not sure to understand what your problem is, but this works just fine :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301]
</IfModule>
The URL http://website.com/hello/world/ redirects me to
http://blog.newexample.com/hello/world/.

How to redirect specific links to https:// everything else to http:// using .htaccess?

I am trying to use htaccess to automatically direct all requests to certain pages to https and everything else to http://
Here is the code I've got the code to force ssl working below
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^va-homebuyers-guide https://domain.com/va-homebuyers-guide/ [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^va-purchase-request https://domain.com/va-purchase-request/ [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^va-streamline-refinance https://domain.com/va-streamline-refinance/ [R=301,L]
This is working as expected and redirects to the ssl versions of those pages. I then tried adding the following to redirect everything else to http:
RewriteCond %{SERVER_PORT} !^80
RewriteCond %{REQUEST_URI} !^va-homebuyers-guide$
RewriteCond %{REQUEST_URI} !^va-purchase-request$
RewriteCond %{REQUEST_URI} !^va-streamline-refinance$
RewriteRule ^(.*)$ http://domain.com/$1 [R,L]
This code results in a redirect loop when going to /va-purchase-request /va-homebuyers-guide and /va-streamline-refinance and does not redirect the other pages at all.
I'm totally stuck with this and any help would be massively appreciated!
Edit:
I also have this code in the .htaccess file added by wordpress... Could it be interfering with the other redirects?
# 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
Replace your .htaccess code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^va-(homebuyers-guide|purchase-request|streamline-refinance)(/.*|)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteCond %{HTTPS} on
RewriteRule (?!^va-(homebuyers-guide|purchase-request|streamline-refinance)(/.*|)$)^.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]