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.
任何http请求(例如pdf)都应该重定向到validate.php,所以如果你调用一个URL(例如http:..... / whatever / whatever / 1.pdf),htaccess应该执行validate.php。
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.
我在网络和stackoveflow上经历了很多例子,但没有运气。由于大多数人的工作都很好,我想我的服务器肯定有问题。
How can I solve this issue?
我该如何解决这个问题?
Thanks
Note: htaccess and validate.php files are stored in the root.
注意:htaccess和validate.php文件存储在根目录中。
- .htaccess - How to redirect all urls to url.php except index.php
- htaccess Redirect All Requests to Index.php Script
- How to redirect all requests to a file, except images using Apache?
- Redirect All Requests To Index.php Using .htaccess
.htaccess - 如何将所有URL重定向到除index.php之外的url.php
htaccess将所有请求重定向到Index.php脚本
如何将所有请求重定向到文件,除了使用Apache的图像?
使用.htaccess将所有请求重定向到Index.php
And many more.
还有很多。
5 个解决方案
#1
1
put this code in your DOCUMENT_ROOT/.htaccess
file:
将此代码放在DOCUMENT_ROOT / .htaccess文件中:
RewriteEngine On
RewriteRule \.pdf$ /validate.php [L,NC]
#2
0
That's all:
# Turn On RewriteEngine
RewriteEngine On
# Set RewriteBase
RewriteBase /
# Redirect any http request to validate.php
RewriteRule . /validate.php [NC,L]
#3
0
Add this to your .htaccess file, inside < IfModule mod_rewrite.c > section
将其添加到
RewriteEngine On
RewriteRule ^ validate.php [L]
#4
0
The problem is you are mixing up Apache htaccess
redirects & 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
.
问题是您正在将Apache htaccess重定向和授权与您期望的应用程序级别行为混合在一起。至少这就是我在这里假设的基于你希望每个请求.pdf在访问.pdf之前通过一个名为validate.php的脚本的事实。
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.
当我说你正在混淆时,强制进行验证的逻辑应该在你的validate.php中或在PHP应用程序的更大框架内。该脚本应该在设置cookie或会话变量或者您可能具有的任何验证方案之后验证用户 - 下载.pdf文件。
Which is all to say, this is not a simple question to answer in the way you describe.
这就是说,这不是一个简单的问题,以你描述的方式回答。
#5
0
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ validate.php [L]
What about this?
那这个呢?
#1
1
put this code in your DOCUMENT_ROOT/.htaccess
file:
将此代码放在DOCUMENT_ROOT / .htaccess文件中:
RewriteEngine On
RewriteRule \.pdf$ /validate.php [L,NC]
#2
0
That's all:
# Turn On RewriteEngine
RewriteEngine On
# Set RewriteBase
RewriteBase /
# Redirect any http request to validate.php
RewriteRule . /validate.php [NC,L]
#3
0
Add this to your .htaccess file, inside < IfModule mod_rewrite.c > section
将其添加到
RewriteEngine On
RewriteRule ^ validate.php [L]
#4
0
The problem is you are mixing up Apache htaccess
redirects & 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
.
问题是您正在将Apache htaccess重定向和授权与您期望的应用程序级别行为混合在一起。至少这就是我在这里假设的基于你希望每个请求.pdf在访问.pdf之前通过一个名为validate.php的脚本的事实。
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.
当我说你正在混淆时,强制进行验证的逻辑应该在你的validate.php中或在PHP应用程序的更大框架内。该脚本应该在设置cookie或会话变量或者您可能具有的任何验证方案之后验证用户 - 下载.pdf文件。
Which is all to say, this is not a simple question to answer in the way you describe.
这就是说,这不是一个简单的问题,以你描述的方式回答。
#5
0
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ validate.php [L]
What about this?
那这个呢?