简体   繁体   English

如何将请求重定向到 .HTACCESS 中的 PHP 文件

[英]How Redirect Requests To A PHP File in .HTACCESS

I want all requests to be transferred via a PHP file.我希望通过 PHP 文件传输所有请求。

My .htaccess file:我的 .htaccess 文件:

RewriteEngine on
RewriteRule . /test.php [L,NE]

And My PHP Code:我的 PHP 代码:

<?php
    header("Location: ".$_SERVER['SCRIPT_URI']);
?>

But without a doubt the result of this code is an infinite loop.但毫无疑问,这段代码的结果是一个无限循环。 The request is given to PHP yy .htaccess.该请求已发送给 PHP yy .htaccess。 and when PHP redirects the user, the user goes to .htaccess again and again.当 PHP 重定向用户时,用户一次又一次地转到 .htaccess。

hope it helps希望能帮助到你

Options -MultiViews

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Next, you process the request already in your index.php.接下来,处理 index.php 中的请求。 No need to use another redirect in php file无需在 php 文件中使用另一个重定向

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

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