Forum Moderators: phranque
RewriteRule ^account(.*)?$ [%{HTTP_HOST}...] [QSA,L]
RewriteRule ^contact(.*)?$ [%{HTTP_HOST}...] [QSA,L]
RewriteRule ^phpmyadmin(.*)?$ [%{HTTP_HOST}...] [QSA,L]
RewriteCond ${HTTP_HOST} !^192.168.0.1$
RewriteRule ^((account¦contact¦phpmyadmin).*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Jim
[edited by: jdMorgan at 2:12 am (utc) on Jan. 5, 2007]
RewriteCond %{HTTP_HOST}!^192\.168\.1\.11$
RewriteRule ^((account¦contact¦phpmyadmin).*)$ [%{HTTP_HOST}...] [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^192\.168\.1\.11$
RewriteRule ^((account¦contact¦phpmyadmin).*)$ [%{HTTP_HOST}...] [R=301,QSA,L]
Cheers everyone!
# If local IP
RewriteCond %{HTTP_HOST} ^192\.168\.1\.11$
RewriteRule ^((account¦contact¦phpmyadmin).*)$ https://192.168.0.1/$1 [R=301,L]
# Else not local
RewriteRule ^((account¦contact¦phpmyadmin).*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Note that neither this nor the code in the previous posts would work if the both HTTP and HTTPS servers were in the same host container; In that case, it would be necessary to check the HTTPS/HTTP status for both rules before redirecting in order to avoid an 'infinite' redirection loop from HTTPS to HTTPS.
There is no need to use [QSA] unless you are Appending something new to the existing Query String. If you don't append something new, then the original query is passed through the rules unchanged by default.
Jim
[QSA] is only needed if you want to Append more query name/value pairs to a URL with a pre-existing query string using RewriteRule.
In the case of the code above, [QSA] does nothing but waste disk space and CPU time. It will work exactly the same with or without [QSA].
See the description of [QSA] in the Flags section of the mod_rewrite documentation, following the description of RewriteRule.
Jim
Append new query to original query
Requested URL: example.com/bool.php?fa&la
Rule: RewriteRule ^bool\.php$ /newbool.php?na [QSA,L]
Resulting URL: example.com/newbool.php?fa&la&na
Remove original query
Requested URL: example.com/bool.php?fa&la
Rule: RewriteRule ^bool\.php$ /newbool.php? [L]
Resulting URL: example.com/newbool.php
Retain original query (default behaviour)
Requested URL: example.com/bool.php?fa&la
Rule: RewriteRule ^bool\.php$ /newbool.php [L]
Resulting URL: example.com/newbool.php?fa&la
Jim