ISAPI Rewrite rule changing https request to http one, for specific page - isapi-rewrite

What should look isapi rewrite rule which can change https to http for a specific page, ex:
https://www.portal.com/mypage to http://www.portal.com/mypage
Regards

Try using:
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} (/mypage)
RewriteRule .? https://%1%2 [R,L]

Related

mod_rewrite: 2 files should always be SSL, the rest always HTTP

I want to ensure that a small number of URLs in my application are always served over SSL; the rest should always be served over HTTP.
My current mod_rewrite ruleset goes like this:
RewriteCond %{HTTPS} off
RewriteRule ^/?account.html$ https://example.com/account.html [L]
RewriteRule ^/?checkout.html$ https://example.com/checkout.html [L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !/account.html$
RewriteCond %{REQUEST_URI} !/checkout.html$
RewriteRule (.*) http://example.com/$1 [L]
The first file in each RewriteCond works OK (account.html in this example). The 2nd file doesn't work - the server is "redirecting in a way that will never complete".
Any ideas on how to make this work? In production there'll be more than 2 SSL-only URLs, likely 7 - 10.
Thanks
You must use R flag to redirect url
RewriteEngine On
# redirect account.html or checkout.html (if http) to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(account|checkout)\.html$ [NC]
RewriteRule ^ https://%{HTTP_HOST}/%1.html [R,L]
# redirect other urls (if https) to http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(account|checkout)\.html$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]
Note: i used R flag, which performs a 302 redirect by default. Feel free to replace [R,L] by [R=301,L] when it works (301 redirect is a permanent redirect and is cached by browsers)

RewriteCond: redirecting all request from specific domains

I'm trying to write a RewriteCond that will redirect a number of domains to a given URL:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?domain2.com$
RewriteRule ^(/)?$ http://www.google.com/ [L]
This is almost working fine. When visiting my domain, I'm redirected to google.com. But when visiting domain1.com/a-sub-folder, it does not match my RewriteCond.
What could I add to the RewriteCond to make them match the above URL?
EDIT1:
Also, is it possible to add some HTTP 301 response to the redirect?
^(/)?$ in the rewrite rule match only an empty path, I replaced it with .*
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?domain2.com$
RewriteRule .* http://www.google.com/ [L,R=301,NC]

ISAPI Rewrite - allow a subdomain to only hit a specific folder

Is there a way with ISAPI v3 to allow a subdomain to only hit a specific folder, and all other requests would redirect to www? I also have some urls under this folder that need to be rewritten. There will also be rewrite rules for valid www urls.
Allow:
http://myaccount.mysite.com/account/
http://myaccount.mysite.com/account/profile/
http://myaccount.mysite.com/account/profile/changeEmail.aspx
Allow, but needs to be rewritten:
http://myaccount.mysite.com/account/edit/123456789.aspx
These should be redirected to www:
http://myaccount.mysite.com/directory/
http://myaccount.mysite.com/folder1/
http://myaccount.mysite.com/folder1/folder2/
etc....
Try using the following:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Host} ^myaccount\.mysite\.com$ [NC]
RewriteRule ^account/edit/123456.aspx$ /otherpage [NC,L]
RewriteCond %{HTTP:Host} ^myaccount\.mysite\.com$ [NC]
RewriteRule ^account/.*$ - [NC,L]
RewriteCond %{HTTP:Host} ^myaccount\.mysite\.com$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [NC,R=301,L]

Helicon ISAPI Rewrite proxy not forwarding requests

I have the following rules defined in my helicon file:
RewriteEngine on
RewriteCond %{HTTP:Host} ^current.mydomain.com$ [NC]
RewriteRule /reg http://another.mydomain.com/registration [NC, P]
When I navigate to the URL http://current.mydomain.com/reg I just receive a blank page. It doesn't seem to be that Helicon is forwarding the request to the other site. Any ideas why?
try using the following istead:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Host} ^current\.mydomain\.com$ [NC]
RewriteRule ^reg http://another.mydomain.com/registration [NC,P]

Conditional URL rewriting

How can I use URL rewriting in .htaccess to redirect to different domains depending on the URL?
Examples:
http://ONE/ to http://TWO/
http://ONE/some_content to http://THREE/some_content
This ought to work if you want to redirect the client:
# http://ONE/ to http://TWO/
RewriteCond %{HTTP_HOST} =one
RewriteRule ^$ http://two/ [R,L]
# http://ONE/some_content to http://THREE/some_content
RewriteCond %{HTTP_HOST} =one
RewriteRule ^(.+)$ http://three/$1 [R,L]
If you prefer to proxy the requests, change the R flag to a P instead.

Resources