complicated anti-hotlinking - .htaccess

I have a quite complicated hotlinking problem. Since I my understanding of .htaccess is kinda terrible, I'll pseudo-code it:
1:Every embedded Image call should redirect to a "do not hotlink" image
2:Every direct hit to an image with let's say: domain.com/folder/IMAGENAME.jpg should redirect to my page containing the image e.g. domain.com/IMAGENAME.html
3:search engines should be unaffacted or at least still be able to crawl them for image searches
Thanks for the help :)

Related

.htaccess, engine rewrite, regardless everything infront, refer to the same folder

It has been a while i've played arround with the engine rewrite functions in the htaccess file.
But due some merged projects and some pretty damn ugly looking url's that would be tomuch work for a simple application to work i've decided to use enginerewrite to make things a bit more pretty.
However, like always there is a catch that i've been struggling with for the past 2 days, the image folder.
To give an example, url's are changing to domain.com/firstpage/firstparam/secondparam/ultimateparam/
the issue here is the images on the page, that are broken because there is no image folder under the uri domain.com/firstpage/firstparam/secondparam/ultimateparam/images/
so my question here is, how can i ignore everything infront of /images/ and make it link to the actual images folder ?
Thanks in advance !
One awnser profided by Amit Verma.
putting a / infront of the path to the image, ex;
<img src="path/to/image.png">
to
<img src="/path/to/image.png">
seems based on the (sub)domain.
Not exactly what the question was, but it solved my issue regardless, thanks!

Keep people from opening pdf directly on my webiste

I am not sure if this is possible, but I figure I would ask.
I have hundred of PDF's stored on my website, and they are all getting indexed directly by Google, so people are doing a search and the engine is taking them directly to the PDF. The issue here is that the PDF's are related to language learning and have audios that go with them. If a visitor goes directly to the PDF, then they never see the audios.
I have another page I have designed which opens up the PDF in an Iframe, and shows the audios right next to them so the users can use it.
So my question is, is it possible to redirect a user who opens:
www.mywebsite.com/something.pdf
And have it redirect them to:
www.mywebsite.com/page-with-audios/
The key here is that the pdf should still open in the IFrame on my domain.
Thanks in advance for any assistance.
If you use routing, you could make a route which has the PDF name as parameter. The route could look something like this:
/{PDF_NAME}.pdf
This could be used to match all PDF's, like example.com/foo.pdf, example.com/bar-baz.pdf. Since you then have the name of the PDF they would like to view, you can redirect them to the /page-with-audio-files with some extra data like the name of the PDF. Then you can handle opening the iFrame.
EDIT
since I now see your question was directed at .htaccess, I think the following might work too.
add this rewrite to your .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z\-]+.pdf)$ /page-with-audio/$1 [L, R=301]
This will make the $1 variable somepdf.pdf if your request url is http://example.com/somepdf.pdf.
Then it redirects the user to http://example.com/page-with-audio/somepdf.pdf so you know which pdf was requested.

AGAIN: how to hide subdirectories in browser bar with htaccess

Sorry to bother you perhaps again, but I can't get it working after trying at least 30 answers already given on this subject!!
I use a somewhat deep directory structure and the I would like to rewrite the address browser bar of all subdirectories been replaced by one: simply (www.)example.com/subdirname. Even if I redirect from within the subdirectories to a higher level.
In other words:
So I have: http://www.example.com/subdirname ----> this what I would like to show every time. Here is also my main index.html located.
Then the structure beneath is e.g. www.example.com/subname/text/image/magazine/xxx.html
I have tried all the REWRITE CODES available (well, practically). But nothing works.
Can and will someone please give me the ultimate answer how to code this in htaccess? Please don't forget to tell me please, in which directory I should place this htaccess (allthough I tried all).
By the way, I don't care about SEO - the (sub-)pages don't have to be 'searchable'.
By the way, this is a site which I like to protect a little against theft, since it concerns my living of bookselling.
Thanks a lot beforehand!
Rokus
There is one way to do this, a frame redirect.
That'll always show the same URL in the address bar - but it's trivial to find the actual URL for anyone with the slightest bit of technical knowledge.
Users will also be unable to link to a specific page or magazine.
If you have intellectual property you want to protect, it might be worth looking into other, more suitable ways to do so.

Trying to create seo friendly url

I'm trying to create friendly url for my site but with no success :(( and i have two questions
The first is:
How to change the url from domain.com/page/something.php to domain.com/something
And the second is:
Will the changes make duplicate content and if how to fix the problem.
Thank you for your time,
Have a nice day
Check out the official URL Rewriting guide: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
You'll be using the simplest use case, Canonical URLs. Assuming you have no other pages that you need to worry about, you can use a rule like this: (note: untested, your usage may vary)
RewriteRule ^/(.*)([^/]+)$ /$1$2.php
While that example might not exactly work for your use case, hopefully reading the guide and my example will help you get you on your way.

Is it possible to redirect with .htaccess based on a date in the URL for static files?

I have a group of images that should be progressively made available on specific dates in the future until the whole set is visible. The images have the date they should be visible as the file name. Anyone with a few insights into the workings of the internet could figure out the pattern in the file names and look at 'future' images before the intended date.
I'm hoping to solve this with .htaccess to prevent spinning up a script every time an image is accessed. Do you think it's possible?
The locale of the server is the only one I'm concerned about.
Thanks :)
Edit:
As an example, at the time of posting this message I'd want this image to serve correctly:
http://domain.com/images/2012-11-20.jpg
But I'd want this one to return a 404, 401 or whatever as it's in the future:
http://domain.com/images/2012-12-06.jpg
I don't seem to fully understand your question, but this link about time-dependant rewriting might give you a little push towards the right direction.
http://www.askapache.com/htaccess/time_hour-rewritecond-time.html
(I am in no way affiliated with this website!)
Rather than having the code change the src of the image, you could dynamically rewrite a fixed image source to the correct daily location:
RewriteCond %{REQUEST_URI} /my/image.jpg
RewriteRule (.*) /images/date/%{TIME_YEAR}-%{TIME_MON}-%{TIME_DAY}.jpg [L]
It's a bit security-by-obscurity, and you lose the ability to long-term cache the image (because come the next day, you'll want the browser to load the new image from the old path), but it might fit your purpose.

Resources