Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


Pages in this thread: 1 | 2 | (show all)   Print Thread
Standard User trolleybus
(regular) Wed 14-Nov-12 12:34:46
Print Post

.htaccess file


[link to this post]
 
I wonder if any visitor to this post can provide a solution to the problem give, it would be fantastic to get a solution! If this is not the right forum to post this query, alternative forum suggestions welcomed.

The .htaccess file shown below is placed in my home directory to foil attempts of deep linking and to thwart viewing the contents of directories. It produces a 403 error for which I have created a custom written page.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk$ [NC]
RewriteRule .*\.(jpg|js|jpeg|gif|bmp)$ - [F,NC]
Options -Indexes

This works just fine. Unfortunately I do not fully understand the syntax or options available within an .htaccess to tweak it slightly so that deep hyperlinking to a single image is possible. A Google search indicated that shown below should achieve this aim but unfortunately it doesn’t work.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk$ [NC]
RewriteRule .*\.(jpg|js|jpeg|gif|bmp)$ http://www.lorage.co.uk/dummy.jpg [R,L]
Options -Indexes

Thoughts from anyone of how to tweak my .htaccess file so that it does everything shown in the top example but additionally allows deep hyperlinking ONLY to http://www.lorage.co.uk/dummy.jpg would be very much welcomed.
Standard User camieabz
(sensei) Wed 14-Nov-12 14:28:58
Print Post

Re: .htaccess file


[re: trolleybus] [link to this post]
 
Does the addition of:

<files dummy.jpg>
order deny,allow
allow from all
</files>

..in the root .htaccess file.

Does that work?

~ Camieabz ~

All Connection Data ~ Some plusnet links

mod'er·a'tion n.
Synonyms: temperance, restraint, modesty.
Standard User trolleybus
(regular) Wed 14-Nov-12 15:10:46
Print Post

Re: .htaccess file


[re: camieabz] [link to this post]
 
In reply to a post by camieabz:
Does the addition of:

<files dummy.jpg>
order deny,allow
allow from all
</files>

..in the root .htaccess file.

Does that work?


I'll keep that thought for another time but as you wrote I was actually working on the issue. I concluded that as my site does not knowing use any png images, then why not convert dummy.jpg to dummy.png?

Did that and my problem was solved, well this time around anyway. All existing features continue to work. So case closed, but thank you for your input.


Register (or login) on our website and you will not see this ad.

Standard User pmb00cs
(eat-sleep-adslguide) Thu 15-Nov-12 07:49:40
Print Post

Re: .htaccess file


[re: trolleybus] [link to this post]
 
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/dummy.jpg$
RewriteRule .*\.(jpg|js|jpeg|gif|bmp)$ - [F,NC]
Options -Indexes

edit: Although I see you have found another solution. (must read the entire thread before responding)

happily chugging along on plusnet and Virginmedia (yes I am greedy)
My web server

Edited by pmb00cs (Thu 15-Nov-12 07:50:37)

Standard User trolleybus
(regular) Thu 15-Nov-12 08:08:13
Print Post

Re: .htaccess file


[re: pmb00cs] [link to this post]
 
Your response comprehensively provides the right answer to my question rather than my workaround, after all on another website there could well be png files present and so my solution only works for lorage.co.uk

I will test your suggested .htaccess file and if it does what it says on the tin, I will adopt the solution accross all other web sites that I have created. It will mean that I can also protect png files with a line that reads:
RewriteRule .*\.(jpg|js|jpeg|gif|bmp|png)$ - [F,NC]

I think it is pointless having 'js' present since it doesn't prevent the contents of that file being visible when carrying out a validation check.

Thank you very much for your input.
Standard User pmb00cs
(eat-sleep-adslguide) Thu 15-Nov-12 20:38:52
Print Post

Re: .htaccess file


[re: trolleybus] [link to this post]
 
I would suggest, if you want to allow hotlinking on more than one file listing them first eg

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/file1.jpg$ [OR]
RewriteCond %{REQUEST_URI} !^/file2.jpg$ [OR]
RewriteCond %{REQUEST_URI} !^/file3.jpg$
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk$ [NC]
RewriteRule .*\.(jpg|js|jpeg|gif|bmp)$ - [F,NC]
Options -Indexes

There is no technical reason for doing it this way around, I just find it easier to read.

Also note the [OR] directive seperating the files, and the lack of the [NC] directive.


Glad I could help.

happily chugging along on plusnet and Virginmedia (yes I am greedy)
My web server
Standard User trolleybus
(regular) Thu 15-Nov-12 20:56:17
Print Post

Re: .htaccess file


[re: pmb00cs] [link to this post]
 
OK, I understand what's going on here and I will keep this information safely.

Ideally I would like to add comments into the file; is that possible and if so, what is the syntax please?
Standard User camieabz
(sensei) Thu 15-Nov-12 21:29:48
Print Post

Re: .htaccess file


[re: trolleybus] [link to this post]
 
Precede a comment line with a hash symbol ( # ).

~ Camieabz ~

All Connection Data ~ Some plusnet links

mod'er·a'tion n.
Synonyms: temperance, restraint, modesty.
Standard User trolleybus
(regular) Fri 16-Nov-12 21:15:45
Print Post

Re: .htaccess file


[re: camieabz] [link to this post]
 
In reply to a post by camieabz:
Precede a comment line with a hash symbol ( # ).


OK so I uploaded this file:

# Version dated 16th November 2012
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/file1.jpg$ [OR]
RewriteCond %{REQUEST_URI} !^/file2.jpg$ [OR]
RewriteCond %{REQUEST_URI} !^/file3.jpg$
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://lorage.co.uk$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lorage.co.uk$ [NC]
RewriteRule .*\.(jpg|js|jpeg|gif|bmp)$ - [F,NC]
Options -Indexes

At first sight all seemed to be well with restricted activities either displaying my custom 403 or 404 page and also I could deep hyperlink to png images. But when going to a page that did not exist, say, nothere.htm it displayed part of a htm file.

I removed what was thought to be just a comment line starting with a # and the full functionality of the .htaccess file returned. So I am back to square one nit knowing how to add comments to these set of instructions.

Any ideas please whether adding comments to an .htaccess file is possible and if so what is the syntax? Help would be appreciated on this one.
Standard User camieabz
(sensei) Fri 16-Nov-12 21:22:01
Print Post

Re: .htaccess file


[re: trolleybus] [link to this post]
 
Suggest you google for .htaccess comments. A hash symbol should work.

~ Camieabz ~

All Connection Data ~ Some plusnet links

mod'er·a'tion n.
Synonyms: temperance, restraint, modesty.
Pages in this thread: 1 | 2 | (show all)   Print Thread

Jump to