Wordpress htaccess rediret from http to https for single page - regex

I'm trying to have my http page to https. The page I want to change is http://dtesolar.ca/estore
I wish I could have https instead of http. I already purchase the ssl certificate, I'm using HTTPS plugin for wordpress but it's not working, so I'm thinking to use the .htaccess file to do it, but not sure for the syntax.
Here's the default thing on htaccess file:
# 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
Please help!

Have your .htaccess like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# force HTTPS for store
RewriteCond %{HTTPS} off
RewriteRule ^estore/ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
PS: You will need to fix links for your JS, css and images on this https URL.

Related

htaccess redirect all subfolders/pages on one domain to matching subfolder on new domain (WordPress)

I have a bunch of domains that all go to the same site and need to be able to redirect domainalias.com/folder/name to website.com/folder/name.
I currently have the following htaccess which works as far as redirecting the root domain, but as soon as I go into a sub-directory or sub-page, it won't redirect:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# Redirect all domains to website.co.uk
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^website.co.uk$ [NC]
RewriteRule ^(.*)$ http://website.co.uk/$1 [L,R=301]
</IfModule>
So to confirm, I want people to be redirected from http://anydomainalias.co.uk/any/sub/folder to http://website.co.uk/any/sub/folder. As it's a WordPress site, I need this to work dynamically. I have 50-odd subdomains so want to avoid having a rule for each one as well (hence the !^website.co.uk rule).
Thanks.
Have redirect rule before default WP routing rule:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all domains to website.co.uk
RewriteCond %{HTTP_HOST} !^website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://website.co.uk/$1 [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
Make sure to test it after clearing your browser cache.

redirect 301 all traffic to homepage

I want to redirect all traffic request uri to homepage of my wordpress page.
I try override default wordpress, but cant get this to work any one can help in this ?
I try following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /wordpress/
RewriteBase /
<If "%{REQUEST_URI} != 'http://127.0.0.1/wordpress/'">
Redirect 301 / http://127.0.0.1/wordpress/
</if>
#RewriteRule (.*) http://127.0.0.1/wordpress/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
You can use this rule just below RewriteBase line:
RewriteCond %{THE_REQUEST} \s/+wordpress/\S [NC]
RewriteRule .+ /wordpress/ [L,R=301]

How to put www in front of a wordpress site url in htaccess?

I have a wordpress site accessed like http://example.com/
but my client wants to have it accessed like http://www.example.com/
I am finding this code as a solution
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ www.domain.com/$1 [L,R=301]
But I am getting an error of redirect loop
Could you please advice me what am i doing wrong?
You're missing http:// from your www forcing rule. Also important is to have your www rule before other WP rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also don't forget to change WP permalinks to have www in Site and Home URLs
You have an easy way to do this inside of wordpress:
Go to your wordpress dashboard and:
1) Select Settings
2) Select option General,
3) Add to your WordPress Address (URL) the www part
4) Add to your Site Address (URL) the www part
And done!

Wordpress: How can I redirect all wordpress tags from subdirectory (subfolder) to another one

I changed my permalinks and it working fine, but I need to redirect old tag folder to archives/tag to not lose links which google indexed
below is my .htaccess file in the root of my recipes site http://foodonia.com
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# 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>
Example: http://foodonia.com/tag/fudge/ should redirect to http://foodonia.com/archives/tag/fudge
I tried to add each one of blow codes but redirect not working
#RewriteRule tag/(.*) archives/tag/$1 [NC,L]
#RewriteRule tag/$ /archives/tag/$1 [NC,L]
#RewriteRule tag/ /archives/tag [L]
even I tried redirect 301 ^/tag/fudge/ http://foodonia.com/archives/tag/fudge/ but it didn't work
I try to search for solution but can't find similar post
You need to use rules in correct order i.e. to use this 301 first before other WP rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule (tag/.*)$ /archives/$1 [NC,NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

HTTPS Force Redirect not working in Wordpress

My Wordpress directory is at www.example.com/blog
I recently changed my entire site to force HTTPS. So my .htaccess file in /blog/ looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I also changed the site URL in Wordpress settings to be HTTPS.
This works perfectly in the homepage, but in any post pages, the end user is able to change to non-secure HTTP, by changing the URL and pressing enter.
For example, they can type directly: http://www.example.com/blog/post-1/ and it will load as HTTP.
What is wrong with my .htaccess file? Where is the loose end?
Change the order of the rules. First redirect to https and then let WP take over all of your requests.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
You can also add these two lines to the wp-config.php
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
So you could easily make conditions for http for dev environment and https for live like so:
if(strpos($_SERVER['HTTP_HOST'], 'livedomain.com') !== FALSE){
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
} else {
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
}