Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1657
  • Last Modified:

Helicon ISAPI Rewrite 3 - Add www preserve query string

I'm trying to write a rule to do 3 things.

Add a www subdomain if it's missing and preserve the https if specified while preserving the query string parameters.

So:

mydomain.com?page=1   should become   http://www.mydomain.com?page=1
http://mydomain.com?page=1     should become   http://www.mydomain.com?page=1
https://mydomain.com?page=1    should become    https://mydomain.com?page=1
http://mydomain.com/search?page=1     should become   http://www.mydomain.com/search?page=1
https://mydomain.com/search?page=1    should become   https://mydomain.com/search?page=1


Any code for this would be greatly appreciated.

0
collages
Asked:
collages
  • 3
1 Solution
 
Brad HoweCommented:
Hi there,
Take a look here. (http://www.helicontech.com/isapi_rewrite/doc/examples.htm)
Redirecting non-www version to www
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
Force to SSL or non-SSL for certain locations
#Redirect non-HTTPS to HTTPS
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R,L]
Cheers,
Hades666
0
 
collagesAuthor Commented:
using:

RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

mydomain.com is redirecting to https://www./
0
 
collagesAuthor Commented:
Ah, I see.  Missing the line at the beginning.

RewriteCond %{HTTPS} (on)?


So it worked with:



RewriteEngine on

#Redirecting non-www version to www
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
0
 
collagesAuthor Commented:
with the addition of

RewriteCond %{HTTPS} (on)?


which was included in the URL provided (which is why it's a complete solution)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now