Keep people from opening pdf directly on my webiste - .htaccess

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.

Related

links includes coma and hash htaccess

I'm using links like that:
find.php?id=1&n=2#loc
I want to my links look like:
but i dont know how to change htaccess and when/where use # to link some place in the page #loc
htaccess:
RewriteRule ^(.*),(.*),(.*)$ $3.php?id=$2&n=$1 [L,NC,NS,NE]
Help lease
The #loc part of the URL is never sent to the server, so there's no way for you to match against it in your htaccess file. Anything starting from the # in the URL is called a fragment and it's used by the browser, the server doesn't know it's even there.

mod_rewrite so a specific directory is removed/hidden from the URL, but still displays the content

I'd like to create a rewrite in .htaccess for my site so that when a user asks for URL A, the content comes from URL B, but the user still sees the URL as being URL A.
So, for example, let's say I have content at mydomain.com/projects/project-example. I want users to be able to ask for mydomain.com/project-example, still see that URL in their address bar, but the browser should display the content from mydomain.com/projects/project-example.
I've looked through several .htaccess rewrite tips and FAQs, but unfortunately none of them seemed to present a solution for exactly what I've described above. Not everything on my domain will be coming from the /projects/ directory, so I'd imagine the rewrite should check to see if the page exists first so it's not appending /projects/ to every url. I'm really stumped.
If a rewrite is not exactly what I need, or if there is a simple solution for this problem, I'd love to hear it.
This tutorial should have everything that you need, including addressing exactly what you are asking: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html . It may just be a matter of terminology.
So, for example, let's say I have content at mydomain.com/projects/project-example. I want users to be able to ask for mydomain.com/project-example, still see that URL in their address bar, but the browser should display the content from mydomain.com/projects/project-example.
With something like:
RewriteRule ^project-example$ /projects/project-example [L]
When someone requests http://mydomain.com/project-example and the URI /project-example gets rewritten internally to /projects/project-example. Note that when this is in an .htaccess file, the URI /project-example gets the leading slash removed when matching.
If you have a directory of stuff, you can use regular expressions and back-references, for example you want any request for http://mydomain.com/stuff/ to map to /internal/stuff/:
RewriteRule ^stuff/(.*)$ /internal/stuff/$1 [L]
So requests for http://mydomain.com/stuff/file1.html, http://mydomain.com/stuff/image1.png, etc. get rewritten to /internal/stuff/file1.html, /internal/stuff/image1.png, etc.

Google Campaign & Analytics URLs with .htaccess

One of our clients is launching a campaign around our city and one of the requirements they want is to track from what item a visitor has scanned in a QR code. To achieve this I have entered this into my .htaccess file:
RewriteRule ^(beermat|poster|flyer)$ /video?utm_source=$1&utm_medium=PrintedMaterial&utm_campaign=VideoCampaign2012 [R=301]
So if anyone scans in the QR code that has the address: http://www.website.com/beermat it redirects to /video with the relevant attributes.
If I have the google analytics code on the /video page this should work, correct?
Try this plugin to see if google-analytics is recording anything.
This way you can see directly if it is working or not.
https://chrome.google.com/webstore/detail/jnkmfdileelhofjcijamephohjechhna
I think it would be better for you to make "poster" a directory, and the index.php inside it should set $_SESSION['found']="poster" then redirect to the main page which would read from the SESSION.
The added benefit is that you're not left with any ugly GET data, just a nice clean url, but the downside is that you have to manually create the directories, so only do this if you have a manageable amount.

Erase '#' from url

UPDATED
I didn't understand how to make this work so I hope you know because I didn't found more solutions:
I have implemented jquery cycle in wordpress with the window.location.hash to make an individual url from each slide (example here http://jquery.malsup.com/cycle/perma.html)
Now I have an indez with some selected photos of differents categories that works with hashes like localhost/prueba/#men/#work61, localhost/prueba/#women/#work15, etc...the trick is that I have also the category /men/ and the photo #work61 permanetly cause the index may change but not the photo in the category indeed. So what I need is change the url without reloading from /#men/ to /men/ and if they share a link they will always go to the right photo and section (did I explain it well ?)
I have been testing many ways to arrive, with history.js and even with the aisle Pushestate but I didn't found the right solution. Lately I have made this with htaccess and it's closely what I need
Options +FollowSymLinks
RewriteEngine On
RewriteBase /prueba/
RewriteRule ^([^/]+)/([^/]+)/$ $1/#$2 [NE,R]
This changes me from localhost/prueba/men/work61 to localhost/prueba/men/#work61 but if I tried to add a hash to the first folder (#men), an also only work if somebody put the link directly
Any idea? Thanks in advance
I think you need to understand the URI specification, section 3.5 https://www.rfc-editor.org/rfc/rfc3986#section-3.5. Essentially, in the context of a web browser displaying HTML documents, the URI fragment (after the #) refers to a subset of the resource (page).
Basically if you removed the # from your URL, you will not be referring to a different subset of the same resource, but another resource entirely. So another page will be requested.

Existing movable type plugin that does URL shortening and redirection?

We send out a newsletter that has URLs in it. Rather than having foreign URLs directly, they all come to our website and then redirect to the outside world.
Right now the redirects are all done with HTML files. My goal is to have them all done with redirects in the .htaccess file. So I want to have the person who is entering all of this data enter it all through the movable type GUI.
My questions:
Is there is plug-in for movable type that already does this?
If not, is there a good template for creating a movable type that allows one to records in the MySQL database?
Thanks.
This could be done in the standard Entry interface in MT. Just dedicate a blog for these redirects. You could make the EntryTitle the redirect and have the EntryBody be the full URL (or use Custom Fields). Then just create an .htaccess template that loops through all the entries.
<mt:Entries lastn="0">
Redirect /<mt:EntryTitle dirify="-"> <mt:EntryBody>
</mt:Entries>
The way I would do this is to create a custom field for the outside URL.
Then I would populate the .htaccess file with something like:
Redirect /
In the above coding, I'm looping through the latest 999 entries and I'm checking if the custom field with the tag 'EntryDataMyCustomField' is filled out.
If it is filled out, then I redirect / to the URL from that custom template.
This is like redirecting say:
/234 to whatever URL you may think of, like say:
http://en.wikipedia.org/wiki/Main_Page

Resources