Solved

.htaccess rewrite rule issue

Posted on 2014-09-08
12
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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
 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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