Forum Moderators: phranque

Message Too Old, No Replies

about RewriteCond/RewriteRule - help needed

         

sadafr

9:44 am on Dec 6, 2006 (gmt 0)

10+ Year Member



hi!
i am trying to use .htaccess to look for a specific cookie. if the cookie is not present send the visitor to a specific URL. and only allow visitor to access contents of particular directory if cookie is set. i have writen following lines in my htaccess

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !TestLogin
RewriteRule ^(.*)$ http://www.example.com/login.htm [R]

i have replaced 2nd line with all of the followings

RewriteCond %{HTTP_COOKIE} !(TestLogin)
RewriteCond %{HTTP_COOKIE} !^TestLogin$
RewriteCond %{HTTP_COOKIE} !^.*TestLogin.*$
RewriteCond %{HTTP_COOKIE} !^TestLogin$ [NC]

but none of this works the way i want it to.. it just redirects the user, doesnt matter if cookie is set or not.. i have checked that cookie is getting set but htaccess/apache cant find it :s

[edited by: jdMorgan at 2:05 pm (utc) on Dec. 6, 2006]
[edit reason] formatting, example.com [/edit]

sadafr

12:25 pm on Dec 6, 2006 (gmt 0)

10+ Year Member



did it,,
atlast find a way to do this....

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !LoggedIn=1
RewriteRule ^(.*)$ http://www.example.com/login.htm [R]

just submitting it for anyone who gets stuck with this

[edited by: jdMorgan at 2:03 pm (utc) on Dec. 6, 2006]
[edit reason] Formatting, example.com [/edit]