0

Any http request (e.g. to pdf) should be redirected to validate.php so if you call an URL (e.g. http:...../whatever/whatever/1.pdf), htaccess should execute validate.php instead.

I went through many examples on web and stackoveflow, no luck yet. Since most work fine for many people, I guess there must be something wrong with my server.

How can I solve this issue?

Thanks

Note: htaccess and validate.php files are stored in the root.

And many more.

3
  • When the answer to your question is the first question that you have linked, I'd like to tell you that searching is not enough. You also need to read what is written in the results. Commented Nov 14, 2013 at 16:22
  • @feeela - How do you know I didn't read! Take that -1 please. Do you think I would risk my server without reading and just doing copy+paste. Commented Nov 14, 2013 at 16:25
  • @anubhava, watch your typos, man :p Commented Nov 14, 2013 at 17:50

5 Answers 5

1

put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On RewriteRule \.pdf$ /validate.php [L,NC] 
Sign up to request clarification or add additional context in comments.

5 Comments

What URL did you use to test this? Make sure this is your first rule.
That should work. Make sure this is first URL. Also can you post your .htaccess in your question?
There wasn't a htaccess file before! I just created one based on your and others' answers.
Is .htaccess enabled on your server?
God bless you my friend. It wasn't and I'm not htaccess nor server admin guy. Enabled it and works perfectly fine. Thanks again.
1

Add this to your .htaccess file, inside < IfModule mod_rewrite.c > section

RewriteEngine On RewriteRule ^ validate.php [L] 

Comments

1

The problem is you are mixing up Apache .htaccess redirects and authorization with your desired application level behavior. At least that is what I am assuming here based on the fact you want every request for a .pdf to go through a script called validate.php prior to accessing the .pdf.

When I say you are mixing things up, the logic to force validation like that should be in your validate.php or within the larger framework of your PHP application. That script should validate the user then—after setting a cookie or a session variable or whatever validation scheme you might have—the .pdf file is downloaded.

Which is all to say, this is not a simple question to answer in the way you describe.

1 Comment

You're right. System was developed long time ago without any documentation and in a mess so everyone can access files without login in the system by just typing name of the file. That's my problem. I cannot rewrite whole system.
0

That's all:

# Turn On RewriteEngine RewriteEngine On # Set RewriteBase RewriteBase / # Redirect any http request to validate.php RewriteRule . /validate.php [NC,L] 

Comments

-1
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ validate.php [L] 

What about this?

1 Comment

No, still able to see the pdf file. Didn't redirect!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.