Forcing https in .htaccess - .htaccess

I try to force https in .htaccess as such:
# 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 %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
# END WordPress
It works when I try www.example.com, but if I try something like www.example.com/contact-us, it is still with http. Is there something wrong with my .htaccess?
Note I do not have access to the cPanel (hosted on crazydomain) nor Wordpress admin. So upload my .htaccess is my only option.

All rules are applied in order. You have rules before the rule handling HTTPS redirects, and those rules all end with [L], meaning that rule evaluation will stop there.
Put your HTTPS redirect first before caring about more detailed pages and files.

Related

Redirect root domain to subfolder

Here is our current .htaccess file with the rules we need to keep but also we need to add a new rule that redirects from the root domain to a subfolder URL
example.com -> example.com/fl/en.html..
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.nz$
RewriteCond %{REQUEST_URI} !^/subfolder [NC]
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(/home.html|/info.html|/flash|/external)
RewriteRule (.*) http://example.com/fl/en.html [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
There doesn't appear to be anything particularly special required, providing you put the directive in the correct place. To redirect the document root (for example.com) to /fl/en.html in .htaccess can be done like so:
RewriteRule ^$ /fl/en.html [R,L]
This just needs to go after the directive that rewrites everything for the host domain.co.nz and before your front-controller. (You could potentially combine this with your existing directive that redirects /home.html, /info.html, etc.)
Your existing rules could be further optimised. Instead of checking the requested URL-path in a RewriteCond directive and allowing everything through in the RewriteRule pattern, it is more efficient to do what you can in the RewriteRule pattern first (since this is what is processed first).
Also, since you are using WordPress, any custom directives you add to .htaccess should be outside of the # BEGIN WordPress section. WordPress itself maintains this section, so any manual customisations you make could be overwritten during an update.
Also, there is no need to repeat the RewriteEngine directive. (The last instance of this directive wins and controls the entire file.)
So, bringing all this together, we have something like:
# Rewrite all requests for domain.co.nz to subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.nz$
RewriteRule !^subfolder /subfolder%{REQUEST_URI} [L]
# Redirect document root to /fl/en.html
RewriteRule ^$ /fl/en.html [R,L]
# Redirect specific paths to /fl/en.html
RewriteRule ^(/home.html|/info.html|/flash|/external) /fl/en.html [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
Note that the above directive (with a single R) is a temporary (302) redirect. Change this to R=301 if this is intended to be permanent, but only once you have tested that it's working OK (to avoid caching issues).
As always, make sure you've cleared your browser cache before testing.

Add-On Domain Redirects to HTTPS

I have a GoDaddy shared hosting account with one main domain that uses SSL and now an add-on domain that I do not want to use SSL. I would like to redirect non-https to https for the main domain BUT NOT for the add-on domain. Both sites use Wordpress.
To be clear, the main domain should use https, the add-on domain should not use https.
The problem I am experiencing is addondomain.com is redirecting to https://addondomain.com.
I know the problem can be fixed through my .htaccess file, and I have made several attempts, but each one ends with the add-on domain redirecting back to the main domain. Any insight as to what I need to change on my .htaccess file would be very much appreciated!
Here is what my .htaccess file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If you want to redirect just the maindomain to https, just add the following condition to your rule :
RewriteEngine On
##if host=="*maindomain.com"##
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$
##and scheme ==http(https off)##
RewriteCond %{HTTPS} off
##then redirect the site to https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Force WWW when URL contains path using .htaccess

I'm having a problem with my URL and my sessions.
I wish to have ALL website pages be forced to use www. As it looks like now, the website looks like this:
www.example.com into www.example.com
example.com into www.example.com
www.example.com/example/ into www.example.com/example/
example.com/example into example.com/example (this is what's wrong)
This is what my .htaccess file 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} ^wewent\.net
RewriteRule ^(.*)$ http://www.wewent.net/$1 [L,R=301,NC]
</IfModule>
# END WordPress
Because the URL does not redirect properly I get double up with sessions one for www and one for the website without. How can I prevent this the best way?
It seems to look ok but one thing you should do is always put your other rules before the wordpress rules as a habit. When using wordpress it should generally be the last set of rules since it does all the routing. Now for the redirect, you should probably use 302temporary which will remove any current cache and verify that your redirects are working properly. Then you can change it to 301 for permanent once it's working correctly.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.wewent\.net [NC]
RewriteRule ^(.*)$ http://www.wewent.net/$1 [L,R=302,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess mod rewrite only with certain domain

I have a website www.website.com and a few domains that redirect to this site. It's a masked redirect, so if I write www.domain.com I can see this url in the browser all the time, but it's actually redirected to subdomain.website.com What I'd like to do is do some .htaccess rewrite rule, so that everything that has domain domain.com will be rewrited to a local file on a server, that is outside of current folder. Let me explain folder structure here:
/
sub/
-- subdomain/
-- test/
---- index.html
web/
Currently everything from www.domain.com goes to /sub/subdomain. In the .htaccess file in /sub/subdomain I want to reroute the request to /sub/test/index.html. So in my .htaccess file in sub/subdomain folder I've tried this:
#start masked redirect
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} domain\.com$ [NC]
RewriteRule .. /test/index.html [L]
#end masked redirect
# 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
Yes, I'm doing all this on top of Wordpress, which I don't really believe matters, but just to be sure I'm posting it.
Unfortunatelly I get Internal Server Error 500
What am I doing wrong, please?
Also: Please don't ask me why I am doing it like this, it has a reason, I'm not uncovering the whole thing I'm trying to do as it is irrelevant to this problem and I really want to focus on this issue here. I just want to know how to fix my .htaccess and it has to be this way. Thank you for your understanding.
This should be in sub/subdomain/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule !^test/index\.html$ /test/index.html [L,NC]
# 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

I need a Wordpress folder to NOT be case sensitive without writing 200 redirects

I have a blog set up at blog.ftj.com/ACSM, it is hosted with Bluehost and their folder structures seem to be case sensitive. Is there something in the .htaccess file that I can adjust so that all possible combinations get redirected to the specific uppercase URL.
Another issue is that it seems that I need to redirect
blog.ftj.com/acsm/
with and without the forward slash.
Here is my current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ACSM/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ACSM/index.php [L]
</IfModule>
# END WordPress
Please submit the full change if you would.
You need to place the following .htaccess in the root dir to rewrite all requests to /ACSM into /acsm
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/acsm$ [NC]
RewriteRule ^(.*)$ /ACSM [L]
RewriteCond %{REQUEST_URI} ^/acsm/(.*)$ [NC]
RewriteRule ^acsm/(.*)$ /ACSM/$1 [L]
</IfModule>
Sorry for delays, have not got an Apache at hands....

Resources