Forum Moderators: phranque
I've a problem. I use Apache 1.3.x with mod_plsql and need to rewrite some dynamic URL's under https and another back under http.
I've try to write simple test rule:
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/pls/f(.*)$
RewriteRule (.*) [%{SERVER_NAME}%{REQUEST_URI}...] [L]
Great. It' works perfectly. Now I need to write complete rule for next actions:
1. Single URL http://example.com/pls/f?p=4550:1:(.*) must be rewrited to
[hostname...]
2. Any other URLs http://example.com/pls/f?p=4550:(.*) must remain under http.
Now I've simplify my task and tried to bit extend first working example as:
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/pls/f\?p(.*)$
RewriteRule (.*) [%{SERVER_NAME}%{REQUEST_URI}...] [L]
Doesn't rewrite.
Kick me, if I stupid - or something else - but help me. How to rewrite one dynamic URL to another dynamic URL?
PS. Yes, I've read all manuals/links/examples I can find, including this site. I found nothing about my task.
[edited by: jdMorgan at 2:14 am (utc) on July 4, 2007]
[edit reason] exmple.com, disable smily-faces in code. [/edit]
The query string must be handled separately in a RewriteCond.
No special provision is needed to pass the query string through; This is the default behaviour unless it is modified or replaced in the RewriteRule substitution URL.
Try:
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{QUERY_STRING} ^p=4550:1:
RewriteRule ^/?pls/f$ https://%{SERVER_NAME}/pls/f [L]
I wasn't sure if this code is for httpd.conf or for .htaccess, so I coded the RewriteRule pattern to work in either.
Jim
# Redirect all non-secure pages to HTTP
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING}!^p=4550:1:
RewriteRule ^/?pls/f$ [%{SERVER_NAME}...] [L]
# Resirect 1 secure page to HTTPS
RewriteCond %{SERVER_PORT}!^443$
RewriteCond %{QUERY_STRING} ^p=4550:1:
RewriteRule ^/?pls/f$ [%{SERVER_NAME}...] [L]
The first rule not working... why? :(
It must works as secured login page:
->put onto https->LOGIN->put back to http
The number "1" in query is login page number. It must be under https, all other pages must not. But after first rule triggered, all other pages remains under https...
PS. This rules uses in httpd.conf
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (2) init rewrite engine with requested uri /pls/f
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (3) applying pattern '^/?pls/f$' to uri '/pls/f'
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (4) RewriteCond: input='80' pattern='^443$' => not-matched
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (3) applying pattern '^/?pls/f$' to uri '/pls/f'
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (4) RewriteCond: input='80' pattern='!^443$' => matched
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (4) RewriteCond: input='p=4550:1:2044720970703470' pattern='^p=4550:1:' => matched
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (2) rewrite /pls/f -> [hostname...]
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (2) implicitly forcing redirect (rc=302) with [hostname...]
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (1) escaping [hostname...] for redirect
*.*.209.9 - - [04/Jul/2007:14:21:50 +0600] [hostname/sid#5b9808][rid#51063e0/initial] (1) redirect to [hostname...] [REDIRECT/302]REDIRECT/302]
I.e, the second rule (put under https) works, but back rule is gone.
Not understanding - why? Error in RuleCond? But where?
No, http->https redirects all works. As seen in mod_rewrite log above.
Only https->http redirect still completely ignoring.
Once more: the rule set are:
# Redirect non-secure pages to HTTP
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING}!^p=4550:1:
RewriteRule ^/?pls/f$ http://%{SERVER_NAME}/pls/f [L]
# Resirect secure pages to HTTPS
RewriteCond %{SERVER_PORT}!^443$
RewriteCond %{QUERY_STRING} ^p=4550:1:
RewriteRule ^/?pls/f$ https://%{SERVER_NAME}/pls/f [L]
# Redirect another Application under HTTPS
RewriteCond %{SERVER_PORT}!^443$
RewriteCond %{QUERY_STRING} ^(p=110:¦p=AppName:LOGIN:[smilestopper])
RewriteRule ^/?pls/f$ https://%{SERVER_NAME}/pls/f [L]
The rule 1 (non-secure pages) is ignored. The rules 2 and 3 works.
The mod_rewrite log contains no information about 1 rule usage.
Why?
Here is a piece of my httpd.conf :
.................
# Include the SSL definitions and Virtual Host container
include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\ssl.conf"
# Include the mod_osso configuration file
#include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\mod_osso.conf"
# Include the Oracle configuration file for custom settings
include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\oracle_apache.conf"
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteLog c:\rewrite.log
RewriteLogLevel 5
# Redirect non-secure pages to HTTP
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING}!^p=4550:1:
..........
So, SSL configured, works perfectly, uses in rewrites TO http correctly. But BACK rewrite rule is ignored.
Here is more complete piece of my Apache config. Where is error? I don't see any.
# Loading rewrite_module here so it loads before mod_oc4j
LoadModule rewrite_module modules/ApacheModuleRewrite.dll
# Include the SSL definitions and Virtual Host container
include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\ssl.conf"
# Include the mod_osso configuration file
#include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\mod_osso.conf"
# Include the Oracle configuration file for custom settings
include "C:\oracle2\product\10.2.0\db\Apache\Apache\conf\oracle_apache.conf"
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteLog c:\rewrite.log
RewriteLogLevel 5
# Redirect non-secure pages to HTTP
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING}!^p=4550:1:
RewriteRule ^/?pls/f$ http://%{SERVER_NAME}/pls/f [L]
# Resirect secure pages to HTTPS
RewriteCond %{SERVER_PORT}!^443$
RewriteCond %{QUERY_STRING} ^p=4550:1:
RewriteRule ^/?pls/f$ https://%{SERVER_NAME}/pls/f [L]
# Redirect Application under HTTPS
RewriteCond %{SERVER_PORT}!^443$
RewriteCond %{QUERY_STRING} ^(p=110:¦p=AppName:LOGIN:[smilestopper])
RewriteRule ^/?pls/f$ https://%{SERVER_NAME}/pls/f [L]
</IfModule>
But - I'm not understand, why http rule still not works? I can't see any obvious mistakes. Did You see? Please, help.
It means, that reverse rules MUST be in context https virtual host, right?
You right, Jim, thanks Alex.
Finally:
Rewrite rules for http-> https must be in common httpd.conf context.
Reverse rules - https-> http must be in context SSL virtual hosts.
--------------------------------------------------------------------
Thank You for Your help, Jim.
[1][[b]edited by[/b]: Yvoinov at 7:17 am (utc) on July 5, 2007][/1]