Forum Moderators: phranque
I was trying to limit access to certain html pages of my site in function of the value of a cookie I set. I was trying to do it with mod rewrite, the idea is the next:
RewriteCond %{HTTP_COOKIE} name_of_cookie=([^;]+)
RewriteCond %{THE_REQUEST}!%1
RewriteRule ^/conflict_directory/.*\.html?$ /errores/notsofast.html
The problem is the second parameter of RewriteCond is a regular expression and I cannot use the value of %1.
Can anybody help?
Thanks in advance.
Please tell us more about the value of the cookie; What is its meaning, and how can its valid values vary? -- This may help us to suggest an alternate approach.
Jim
in order to allow the visitor to get the html, the value of the cookie must be the same that appears on the URL:
/conflict_directory/VALUE_OF_THE_COOKIE/path_to_file/file.html
I've implemented a partial solution:
RewriteCond %{HTTP_COOKIE} curso=([^;]+) [NC]
RewriteRule ^/conflict_directory/([^/])+/(.*.html?) /mir8/lecciones/%1/$2
As I cannot compare two variables I redirect to the correct file if the visitor has the appropiate cookie, and in other case he is redirected to the directory where he has access, normally getting a Not Found Error unless the path is the same, but he doesn't get the file he isn't allowed to get.
This gives me the functionality, but I would like to be able to send him to an special error page.
Any idea?
Thanks for your interest.
# Get cookie value if it exists
RewriteCond %{HTTP_COOKIE} curso=([^;]+)
# if valid page exists as a file
RewriteCond %{DOCUMENT_ROOT}/mir/lecciones/%1/$2 -f
# internally rewrite to valid page
RewriteRule ^/conflict_directory/([^/])+/(.+\.html?)$ /mir8/lecciones/%1/$2 [L]
# else rewrite to special page
RewriteRule ^/conflict_directory/([^/])+/(.+\.html?)$ /special_page.html [L]