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

x
?
Solved

Rewriting URL

Posted on 2012-09-21
8
Medium Priority
?
291 Views
Last Modified: 2012-09-24
Hi All,

   I want to rewrite anything (root or subfolder) of the following domain (as an example):  I have other rewrite rules that I don't want to conflict with for the shopping cart.

http://www.test.com to http://test.com
and https://www.test.com to http://test.com

   I screwed up on my SSL and didn't realize I should've requested www.<domain>.com.  In IE it is coming up invalid certificate when I goto www.<domain>.com

Thanks - Zack
0
Comment
Question by:zack4x4
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:grahamnonweiler
ID: 38424150
Create/add to your .htaccess the following, replacing the domain name with yours.

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI} [R=301,L]

Open in new window


Please note these must be at the top of your .htaccess / rewrites - or else it won't work
0
 
LVL 4

Author Comment

by:zack4x4
ID: 38424156
Hmmm for some reason the top works but the https doesn't.
0
 
LVL 16

Expert Comment

by:grahamnonweiler
ID: 38424303
Ok try this instead:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI} [R=301,L]

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 4

Author Comment

by:zack4x4
ID: 38424742
We're making progress lol.

It works on firefox but not on IE.  Is there some sort of stupid security thing in IE that you know of?
0
 
LVL 16

Expert Comment

by:grahamnonweiler
ID: 38425015
What does it do on IE?

And which version of IE?
0
 
LVL 4

Author Comment

by:zack4x4
ID: 38425078
it doesn't do anything it loads the url as usual disregarding the htts rewrite but the http works fine
0
 
LVL 16

Accepted Solution

by:
grahamnonweiler earned 2000 total points
ID: 38425852
Try reversing the order of the rewrites:
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI} [R=301,L] 

Open in new window

However, the correct method should be based on using %{HTTPS}  as this is more resiliant to other settings that may be present in the HTTP.CONF file for your server.
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI}%{QUERY_STRING}  [R=301,L] 

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI}%{QUERY_STRING}  [R=301,L] 

Open in new window

0
 
LVL 4

Author Comment

by:zack4x4
ID: 38428853
Ok I understand what's happening with IE.  It's popping up an invalid SSL cert (because the SSL cert isn't good for www.  Once you acknowledge the invalid cert the rewrite does work.  

I appreciate your help!
Thanks Zack
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

575 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