Solved

.htaccess rewrite rule issue

Posted on 2014-09-08
12
167 Views
Last Modified: 2014-09-10
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
Comment
Question by:collinsn
  • 6
  • 5
12 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40309742
Did you try this?
RewriteRule http://www.testdomain.co.uk/$ https://testdomain.co.uk/$1 [R,L]

Open in new window

0
 
LVL 1

Author Comment

by:collinsn
ID: 40310008
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
 
LVL 18

Expert Comment

by:Hube02
ID: 40311032
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
 
LVL 1

Author Comment

by:collinsn
ID: 40311471
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
 
LVL 18

Expert Comment

by:Hube02
ID: 40311728
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
 
LVL 1

Author Comment

by:collinsn
ID: 40313171
Hi Hube,

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

any other suggestions

Thx
Nev
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 18

Expert Comment

by:Hube02
ID: 40313187
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
 
LVL 1

Author Comment

by:collinsn
ID: 40313220
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
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
ID: 40313272
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
 
LVL 1

Author Closing Comment

by:collinsn
ID: 40315161
Really went all out, thx
0
 
LVL 1

Author Comment

by:collinsn
ID: 40315165
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
 
LVL 18

Expert Comment

by:Hube02
ID: 40315310
change the R flag to R=301

[R=301,QSA,L]
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now