Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with rewrite rule 1

Status
Not open for further replies.

J1mbo

Programmer
Dec 12, 2002
93
US
I have the following working rules in my httpd.conf for redirecting http to https based on the URI:

### Redirect port 80 to port 443 (ssl) for secure content
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^.*(password|phpmyadmin).*$ [NC]
RewriteRule ^.*$ [L]

I can't get the inverse rule to work, which i want to use to move people from https to http for non-secure content:

### Redirect port 443 to port 80 for all NON password protected pages
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^.*(password|phpmyadmin).*$ [NC]
RewriteRule ^.*$ [L]

Any assistance would be appreciated.
 
It looks to me like the !^.*(password|phpmyadmin) condition may be the problem. Specifically, The !^ looks like it is saying that the condition does not begin with a start of line.

If I recall my regular expressions, I think the type of condition you are after is more of a [^(password|phpmyadmin)], where the [^ ] is an exclusionary condition. Someone who is better at regex should be able to give you the correct syntax, if I got it wrong.
 
Thanks for the reply.

I can't seem to find any good documentation on the use of "!" w/ mod_rewrite, but i thought it was correct from what i've seen in other examples. I'll look into this more closely though. The [^ ] works for negative character classes, but it doesn't work in this situation.

 
Hi

J1mbo said:
I can't seem to find any good documentation on the use of "!" w/ mod_rewrite
httpd.apache.org said:
You can prefix the pattern string with a '[tt]![/tt]' character (exclamation mark) to specify a non-matching pattern.
httpd.apache.org said:
In [tt]mod_rewrite[/tt] the [tt]![/tt] character can be used before a regular expression to negate it. This is, a string will be considered to have matched only if it does not match the rest of the expression.
I would say, your original code is correct and the error comes from somewhere else.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top