gpt4 book ai didi

php - htaccess 重定向隐藏 php 扩展或传递参数

转载 作者:搜寻专家 更新时间:2023-10-31 21:11:09 24 4
gpt4 key购买 nike

我正在使用主 index.php 文件来处理大部分请求,所以我的基本 .htacess 看起来像 this one :

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L]

但我有一些请求(如/signin 或/signout)需要直接从同名的 .php 文件(/signin.php 和/signout.php)处理。

所以我的 .htaccess 规则需要是:“if %{REQUEST_FILENAME}.php does not exists redirect to /index.php?page=$1 else redirect to %{REQUEST_FILENAME}.php”。

我该怎么做?

最佳答案

用这个替换你的代码:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA]

这会将不是有效文件或目录且在您的文件系统中不存在匹配的 .php 的所有内容发送到 /index.php

关于php - htaccess 重定向隐藏 php 扩展或传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19223226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com