Forum Moderators: phranque

Message Too Old, No Replies

htaccess HTTPS to HTTP redirect keeping friendly URLs

I need to redirect https to http and keep my rewrite rules

         

acisneros

6:41 pm on May 24, 2012 (gmt 0)

10+ Year Member



Hello, hope someone can help me out.

I have an htaccess files which handles friendly url and some other rewrite rules.
To be specific, this is what the htaccess file does:

domain.com to www.domain.com
buy-product.html instead of productpage.php?productname=myproduct

I need to do https to http, the problem is on this case: : [example.com...] to http://www.example.com/buy-product.html

When the redirect is done, it is done in this way:
http://www.example.com/productpage.php?productname=myproduct

If I do example.com to www.example.com I can keep the buy-product.html portion.

Here is my htaccess code, I really hope you can help me out.
I am using Helicon Ape under IIS7

# Helicon Ape version 3.0.0.76

rewriteengine on

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
rewriterule ^buy-([^/]*)\.html productpage.php?productname=$1 [L]
rewriterule ^allproducts-(.*)\.html$ products.php?beginstring=$1&category=$2

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)/(.*)\ HTTP/ [NC]
RewriteRule ^.*$ http://%{SERVER_NAME}/%1/%2 [R=301,L]

errorDocument 404 /404.cfm

[edited by: incrediBILL at 7:13 am (utc) on May 25, 2012]
[edit reason] dupe threads fixed [/edit]

g1smd

8:34 pm on May 24, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




There are a LOT of issues with your code. These include rules in the wrong order, missing flags, and too many (.*) patterns.

[edited by: incrediBILL at 7:12 am (utc) on May 25, 2012]

acisneros

3:12 pm on May 25, 2012 (gmt 0)

10+ Year Member



I see...but how can I replace this kind of patterns: ^(.*)$

lucy24

9:15 pm on May 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am using Helicon Ape under IIS7

Shouldn't this be in the IIS forum? For some reason it's in Microsoft instead of "Code and Content".

I see...but how can I replace this kind of patterns: ^(.*)$

^(.*)$ in that exact form is OK, except that the anchors here are redundant. By default, Regular Expressions will start capturing as soon as they can and go on as long as they can.

The form
blahblah/(.*)
is also OK: it means "capture anything after the literal string 'blahblah/'."

The problem form is
(.*)morestuff
because of the "as long as it can" factor.

For example in
^[A-Z]{3,9}\ /(.*)/(.*)\
you need to figure out exactly what you're aiming for in each capture. You know what you want but the server is only a stupid computer and has no idea. What if the request contains more than one interior slash?

acisneros

9:44 pm on May 25, 2012 (gmt 0)

10+ Year Member



I understand, makes sense.

I used an example I saw on another post and seemed to work welll exacpt that redirect was done to http://www.example.com/buy-product.html?productname=searchedproduct

I have tried capturig whatever is in front of .com/ also I am not sure what HTTP / and the end of the expression is for

g1smd

10:00 pm on May 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am not sure what HTTP/ and the end of the expression is for

THE_REQUEST contains the literal GET request in the HTTP header sent by the browser or bot.

This is in the form:
GET /index.php?param=value HTTP/1.1


Use the Live HTTP Headers extension for Firefox to see this in action.