?
Solved

.htaccess rewrite rule issue

Posted on 2014-09-08
12
Medium Priority
?
173 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 Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 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