Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

.htaccess rewrite rule issue

Hi,

I need to be able to rewrite the following.

http://www.testdomain.co.uk/  to https://testdomain.co.uk/

Without rewriting the following https://clients.testdomain.co.uk/ to https://testdoamin.co.uk/ as this is what is happening now

Current .htaccess is

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://testdomain.co.uk/$1 [R,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

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from a.b.c.d

Open in new window


Many thanks
Nev
0
collinsn
Asked:
collinsn
  • 6
  • 5
1 Solution
 
Randy PooleCommented:
Did you try this?
RewriteRule http://www.testdomain.co.uk/$ https://testdomain.co.uk/$1 [R,L]

Open in new window

0
 
collinsnAuthor Commented:
Hi Randy,

But this would not accommodate the rewrite for http://testdomain.co.uk/ to https://testdomain.co.uk/

Also yours will not work.

Nev
0
 
Hube02Commented:
Try this, place the entire thing before the standard WP rewrites.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^clients\. [NC]
RewriteRule ^(.*)$ https://testdomain.co.uk/($1) [R,QSA,L]

Open in new window


The only things you were really missing in yours was turning the engine on and the check for the clients subdomain. I also added the QSA flag, just in case.
0
Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

 
collinsnAuthor Commented:
Ok Hube we are getting there, but the clients.testdomain.co.uk also needs to be https://

Currently its not redirecting to clients.testdomain.co.uk to https://clients.testdoamin.co.uk/

So I need testdoamin.co.uk redirected to https:// and also clients.testdoamin.co.uk also https://

Thx
Nev
0
 
Hube02Commented:
ah, for some reason I thought you wanted to leave the clients one alone, in that case. Change the line that's checking for the clients sub domain and then use the captured results in the rewrite rule.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/($1) [R,QSA,L]

Open in new window

0
 
collinsnAuthor Commented:
Hi Hube,

I really appreciate your support, but this is no better.

any other suggestions

Thx
Nev
0
 
Hube02Commented:
I don't understand why. That should be capturing the entire host name and path and redirecting whatever it was to https if https is off.

ahhhh, Hmmm, there is an error in my second on, but it should have cause a 404? I had () around the $1 above, don't know why I did that, fingers hitting keys of their own choosing.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R,QSA,L]

Open in new window

0
 
collinsnAuthor Commented:
Hi,

I did notice the error and remove, so I've left with the following....

Direct Copy&Paste
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R,QSA,L]

Open in new window


However

Entered - Rewrite Result - Require.

http://www.testdomain.co.uk  - https://www.testdoman.co.uk/ - https://testdomain.co.uk/  NOK
http://testdomain.co.uk - https://testdomian.co.uk - https://testdomain.co.uk OK
http://clients.testdomain.co.uk - https://clients.testdomain.co.uk - https://clients.testdomain.co.uk  OK

Thx
Nev
0
 
Hube02Commented:
may have to do it a little at a time
RewriteEngine On

#if not https
RewriteCond %{HTTPS} off
#does not start with clients
RewriteCond %{HTTP_HOST} !^clients\. [NC]
#is testdomain.co.uk with or without the www
RewriteCond %{HTTP_HOST} ^(www\.)?testdomain\.co\.uk$ [NC]
#redirect to https domain without the www
RewriteRule ^(.*)$ https://testdomain.co.uk/($1) [R,QSA,L]

#if not https
RewriteCond %{HTTPS} off
#and host starts with clients.
RewriteCond %{HTTP_HOST} ^clients\.
#redirect to https client site
RewriteRule ^(.*)$ https://clients.testdomain.co.uk/($1) [R,QSA,L]

#if is https
RewriteCond %{HTTPS} on
#and domain starts with www
RewriteCond %{HTTP_HOST} ^www [NC]
#redirect to non www site
RewriteRule ^(.*)$ https://testdomain.co.uk/($1) [R,QSA,L]

RewriteEngine Off

Open in new window

0
 
collinsnAuthor Commented:
Really went all out, thx
0
 
collinsnAuthor Commented:
Just one small thing, how do you make these 301 permanent redirects to google, so your current page rankings are not effected.

Thx
Nev
0
 
Hube02Commented:
change the R flag to R=301

[R=301,QSA,L]
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now