简体   繁体   English

htaccess,如果从特定的.php 文件重定向

[英]htaccess, If redirected from specific .php file

I have got a .htaccess file which isn't working as it should.我有一个 .htaccess 文件无法正常工作。

This is in my PHP file (access.php)这是我的 PHP 文件 (access.php)

header("Location: https://example.com/images/flower.jpg");

This is what I have in my .htaccess这就是我的 .htaccess

<FilesMatch "\.(jpe?g|png)$">
RewriteEngine On
RewriteCond "%{HTTP_REFERER}" "!https://example\.com/scripts/access\.php" [NC]
RewriteRule https://%{HTTP_HOST}/management/htaccess/access\.php?%{QUERY_STRING} [R]
</FilesMatch>

What I want to accomplish: I only want the https://example.com/images/flower.jpg to work if it was redirected by https://example.com/scripts/access.php .我想要完成的事情:如果https://example.com/scripts/access.ZE1BFD762321E409CEE4ZAC0B6E8重定向,我只希望https://example.com/images/flower.jpg能够工作And if it wasn't redirected by access.php, then I want it to go back to access.php.如果它不是由 access.php 重定向,那么我希望它到 go 回到 access.php。

Fixed it with:修复它:

<FilesMatch "\.(jpe?g)$">
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$ 
RewriteRule ^ /scripts/access\.php?%{QUERY_STRING} [L,NC]

RewriteCond %{HTTP_REFERER} !example.com/scripts/access\.php [AND]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^ /scripts/access\.php?%{QUERY_STRING} [L,NC]
</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM