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.

Community
  • 1
  • 1
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • 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. – feeela Nov 14 '13 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. – BentCoder Nov 14 '13 at 16:25
  • @anubhava, watch your typos, man :p – Charles Nov 14 '13 at 17:50

5 Answers5

1

put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule \.pdf$ /validate.php [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
1

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

RewriteEngine On
RewriteRule ^ validate.php [L]
vitorsdcs
  • 682
  • 7
  • 32
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.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • 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. – BentCoder Nov 14 '13 at 16:31
  • Well if that’s the case, I am unclear how anyone can solve this issue. There are other answers providing Apache redirect/rewrite options but I doubt that would solve anything. – Giacomo1968 Nov 14 '13 at 16:36
0

That's all:

# Turn On RewriteEngine
RewriteEngine On
# Set RewriteBase 
RewriteBase /
# Redirect any http request to validate.php
RewriteRule . /validate.php [NC,L]
Reeno
  • 5,720
  • 11
  • 37
  • 50
-1
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ validate.php [L]

What about this?

AdRock
  • 2,959
  • 10
  • 66
  • 106