Andante88
Andante88

Reputation: 65

htaccess redirect for folder-only URL

I would like to know how a full pathname call for a pdf can be served showing only the enclosing folder URL. This is for keeping the URLs minimal while doing some logging.

The file structure for each in a series of documents is (example):

/mysite.com/docs/doc-4-5/
    index.php
    document-4-5.pdf

The index does some logging, then redirects:

doLogging(); 
header('Location:document-4-5.pdf');

This works. A call to the folder returns the pdf. But the return URL includes the pdf's full pathname, and I would like it to show only the enclosing folder name, so when you get the pdf, the URL you see is (example):

/mysite.com/docs/doc-4-5/

Thus, refresh calls for the pdf, or any full pathname call to it, will always go through the index.

It seems this can be done with redirect, but I have not been able to do it, and will appreciate guidance.

Thank you.

Upvotes: 0

Views: 89

Answers (1)

Andante88
Andante88

Reputation: 65

Thank you. This is working:

doLogging();
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="document-4-5.pdf"');
readfile('document-4-5.pdf');

Clicking the pdf's name (link) in the main directory does the download without opening the pdf in the browser, as suggested.

Upvotes: 0

Related Questions