RewriteRule not working properly

Discuss practical ways rearrange URLs using mod_rewrite.

RewriteRule not working properly

Postby markthien » Sun Nov 09, 2008 10:30 pm

Hi guys,

My rewrite rule is like below:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sdalk\.com$
RewriteRule (.*) http://www.sdalk.com$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^/secure(.*) https://%{SERVER_NAME}/secure$1 [R,L]

when I go to

https://www.sdalk.com

it doesn't rewrite to

http://www.sdalk.com

which it suppose to. however, when I go to

http://www.sdalk.com/secure/msend.html

then it able to rewrite to

https://www.sdalk.com/secure/msend.html

ok all I need is when user browse to the folder "secure", it should be a secure connection aka https, which is working now and other than that all the pages shouldn't be https. if user try to enter, for example, https://www.sdalk.com/home.html, it must be rewrite to http://www.sdalk.com/home.html

Appreciate someone could assist me on this issue. Thanks in advance !

regards,
Mark Thien
markthien
 
Posts: 7
Joined: Mon Sep 08, 2008 11:28 pm
Location: Singapore

Postby richardk » Mon Nov 10, 2008 2:38 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(secure(/.*)?)$ https://www.example.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} !^80$
RewriteRule !^secure(/.*)?$ http://www.example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{SERVER_PORT}s ^80s|443(s)$
RewriteRule ^(.*)$ http%1://www.example.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby markthien » Fri Nov 14, 2008 3:28 am

hi richardk,

I tried your suggestion and it's now working when I tried to enter

https://www.sdalk.com/home.html

then it's able to forward to

http://www.sdalk.com/home.html

however, when I tried to access

http://www.sdalk.com/secure/msend.html

and it doesn't forward to

https://www.sdalk.com/secure/msend.html

one more thing is that when I browse to

https://www.sdalk.com/secure/msend.html

it will redirect to

http://www.sdalk.com/secure/msend.html

appreciate if you could further assist me on this issue. Thanks !
markthien
 
Posts: 7
Joined: Mon Sep 08, 2008 11:28 pm
Location: Singapore

Postby richardk » Fri Nov 14, 2008 1:08 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(secure(/.*)?)$ https://www.example.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} !^80$
RewriteRule !^secure(/.*)?$ http://www.example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby markthien » Fri Nov 14, 2008 7:35 pm

still the same result !
markthien
 
Posts: 7
Joined: Mon Sep 08, 2008 11:28 pm
Location: Singapore

Postby richardk » Sat Nov 15, 2008 9:27 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTPS} =on
RewriteRule ^(secure(/.*)?)$ https://www.example.com/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule !^secure(/.*)?$ http://www.example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby markthien » Sat Nov 15, 2008 6:01 pm

even worst ... PAGE NOT FOUND !
markthien
 
Posts: 7
Joined: Mon Sep 08, 2008 11:28 pm
Location: Singapore

Postby richardk » Sun Nov 16, 2008 9:15 am

Which URL is giving that page not found error? You need to give more information or i won't be able to help you.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 18 guests

cron