Solved

.htaccess rewrite rule issue

Posted on 2014-09-08
12
171 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
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux boot cd to do hardware report on PC? 3 97
How to fix Dual Server Conflict GitLab vs Apache2 3 57
Logrotate Every Saturday 5 42
cmake and message 1 21
The purpose of this article is to demonstrate how we can use conditional statements using Python.
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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