Forum Moderators: phranque
I would like all pages to go to http except for a few direct links. I was able to do this but I would also like to redirect all https links to http if they are not one of the direct links that should be https.
I am also using the zend framework redirects and a redirect to make sure that the www is present. Here is my htaccess file:
==
#redirect https to http
#RewriteCond %{https} !=off
#RewriteRule ^/?(.*) http://www.example.org/$1 [R=301,L]
#redirect to www.example.org
RewriteCond %{HTTP_HOST} ^example.org$ [OR]
RewriteRule ^(.*)$ "http\:\/\/www\.example\.org\/$1" [R=301,L]
#redirect specific urls to https
RewriteCond %{https} !=on
RewriteCond %{REQUEST_URI} ^/parents/tuition [NC]
RewriteRule ^/?(.*) [example.org...] [R=301,L]
#zend framework
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
==
The file works without the first two lines except that it doesn't redirect https pages to http when they should not be secure. With the first two lines, I get an infinite loop.
I appreciate any help.
[edited by: jdMorgan at 12:47 pm (utc) on July 8, 2009]
[edit reason] example.org -- Please see TOS. [/edit]
# Externally redirect non-secure page requests from https to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^parents/tuition/
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L]
#
# Externally redirect /parents/tuition/ page requests from http to https
RewriteCond %{SERVER_PORT} !=443
RewriteCond $1 ^parents/tuition/
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
#
# Externally redirect all non-canonical hostname requests to www.example.org preserving http/https
RewriteCond %{HTTP_HOST} !^(www\.example\.org)?$
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦[0-9]+>s)$
RewriteRule ^(.*)$ http%2://www.example.org/$1 [R=301,L]
#
#zend framework
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /index.php [L]
Jim
# Externally redirect all non-canonical hostname requests to www.example.org preserving http/https
RewriteCond %{HTTP_HOST} !^(www\.example\.org)?$
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦[0-9]+>s)$
RewriteRule ^(.*)$ http%2://www.example.org/$1 [R=301,L]
On my local server, the page gets redirected to [example.org...] but then stops there because I don't have a secure server setup.
If I physically type that address in a browser on the actual server, it ends up at http://www.example.org/index.php.
Typing in http://www.example.org/parents/tuiton just stays on http://www.example.org/parents/tuiton instead of being redirected to [example.org...]
It seems that this rule is overriding the previous rule and is always ending up at http.
I think what you gave me works but there is some conflict with the URL rewriter for the Zend Framework. I will have to read up on that and see if I can't figure it out what is happening.
Thanks for your help.
In that case, the following mod will fix it:
# Externally redirect non-secure page requests from https to http
RewriteCond %{SERVER_PORT} =443
[b]RewriteCond %{THE_REQUEST} !^[A-Z]+\ /parents/tuition/[/b]
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L]
#
# Externally redirect /parents/tuition/ page requests from http to https
RewriteCond %{SERVER_PORT} !=443
[b]RewriteCond %{THE_REQUEST} ^[A-Z]+\ /parents/tuition/[/b]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
#
# Externally redirect all non-canonical hostname requests to www.example.org preserving http/https
RewriteCond %{HTTP_HOST} !^(www\.example\.org)?$
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦[0-9]+>s)$
RewriteRule ^(.*)$ http%2://www.example.org/$1 [R=301,L]
#
#zend framework
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /index.php [L]
Jim