Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-02-26 21:25:31
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
htaccess redirect to section
Suppose I want to redirect all requests that are directly coming from :
http://mysite.com/images/.*\.jpg
but only allow those, that are coming from:
http://mysite.com/lightroom/.*
to access directly any images at:
http://mysite.com/images/.*\.jpg
( Note: My intention here is not hotlink prevention )
I have been thinking that this could be done with the QUERY_STRING variable like that:
RewriteCond %{QUERY_STRING} ^mysite1\.dev/images$
RewriteRule ^mysite\.dev/images http://mysite.dev/lightroom/ [R,L]
but it doesn’t work.
My suspicion was, that may be TXP’s own rewrite logic interferes with it, but I have no clue.
( In other words: Only when the User is currently in the lightroom section then he shall be allowed to access direct image URL’s, in all other cases, he shall be redirected to the section front page )
Any Ideas ?
regards, marios
Last edited by marios (2007-02-26 21:29:47)
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
Re: htaccess redirect to section
I don’t understand…
Offline
#3 2007-02-26 22:27:40
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: htaccess redirect to section
You’d need to check the referrer string, not the query string.
Alex
Offline
#4 2007-02-26 22:39:13
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: htaccess redirect to section
The example is wrong in any case (QUERY_STRING) can not be used.
To put it more simple.
Suppose, I have a gallery section on a TXP Site with a default .htacess file.
Now I want to grant access to any image files in that gallery section only for those visitors, that are allready in the gallery Section.
To give a practical example:
Visitor X is currently browing the gallery section.
(His current Browser URL is : http://example.com/gallery/(etc)
He follows a link that points to the individual image file, which is:
http://example.com/images/somepic.jpg
The aim is to allow him to follow the link.
Visitor Y is the mother in law, that we don’t want in the kitchen.
She places a guessed image URL directly in the Browser, which is also:
http://example.com/images/somepic.jpg
The aim here is to exclude all Visitors of type Y
( But instead of giving them a 403, redirect those requests to the gallery section front page )
I hope that explains better what I want.
( I am currently resarching all the htaccess tutorial. I had one superb one, that also explains all the flags and variables, but I can’t find it )
regards, marios
Last edited by marios (2007-02-26 22:59:55)
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
#5 2007-02-27 00:39:07
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: htaccess redirect to section
This seems to work:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite1\.dev/images/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://mysite1.dev/lightroom/ [R,L]
(at least locally, however, there are a couple of downsides to this, since the referer variable can not be relied on for all the cases)
regards
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
#6 2007-02-27 09:54:55
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: htaccess redirect to section
No it doesn’t.
This seems to be correct, but however still doesn’t work, mainly I think, because there is not even a referer that would make
the rewrite condition match in this case.
RewriteCond %{HTTP_REFERER} ^$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?mysite.com/images/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://mysite.com.com/lightroom/ [L,R]
I still didn’t find anything that would work as a simple rewrite rule.
regards, marios
Last edited by marios (2007-02-27 09:56:00)
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
#7 2007-02-28 12:00:04
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: htaccess redirect to section
bumping this thread.
It can not been done, relying on mod_rewrite.
regards, marios
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
#8 2007-02-28 23:08:35
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: htaccess redirect to section
Er, aren’t you missing something?
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com/images/.*$ [NC]
RewriteRule .*\.(gif|jpg|png)$ http://mysite.com/lightroom/ [L,R,NC]
Offline
#9 2007-03-01 20:19:25
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: htaccess redirect to section
Yes, @mary, thanks. The negates and case-insensitivity flags where missing from the example.
Unfortunately, I haven’t been able to reproduce any working example neither locally nor on TXD on any browser.
(Nor did I see anyone elsewhere)
Could be a variety of factors there.The original VH containers ( Order directives ), the fact, that I have subdomains, but plus also the fact, that http_referer is unreliable in general.
Apaches error logs remain silent about this also.
regards, marios
Last edited by marios (2007-03-01 20:20:23)
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
Pages: 1