Php 双重访问规则
我正在尝试执行双重重定向,但无法获得正确的逻辑: 1。如果页面存在,请忽略所有规则 2.如果页面不存在,则添加.php扩展名(但将其隐藏在URL栏中) 3.如果页面不存在且不存在.php扩展名,则重定向到单个页面(query.php),并将键入的内容作为变量参数附加到url栏中(并在url栏中点击) 文件结构示例: index.phpPhp 双重访问规则,php,apache,.htaccess,redirect,Php,Apache,.htaccess,Redirect,我正在尝试执行双重重定向,但无法获得正确的逻辑: 1。如果页面存在,请忽略所有规则 2.如果页面不存在,则添加.php扩展名(但将其隐藏在URL栏中) 3.如果页面不存在且不存在.php扩展名,则重定向到单个页面(query.php),并将键入的内容作为变量参数附加到url栏中(并在url栏中点击) 文件结构示例: index.php pricing.php query.php 示例测试: Htaccess 实际测试: 好 [domain]/pricing.php -> [domain]/
pricing.php
query.php
示例测试:
Htaccess 实际测试: 好
[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page)
[domain]/pricing -> [domain]/pricing (showing the pricing.php page)
[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse_php appended)
坏的
[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page)
[domain]/pricing -> [domain]/pricing (showing the pricing.php page)
[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse_php appended)
我上面的.htaccess文件做了我希望它做的一切,除了当我重定向到query.php时抛出$\u GET变量时,它显示了附加的“\u php”。我假设是因为前面的规则…请尝试以下方法。这些条件/规则集特定于您列出的要求,并为您提供对向用户提供的服务的细粒度控制
重新编写引擎打开
#提供请求的文件(如果存在)
RewriteCond%{REQUEST_FILENAME}-f
重写规则^-[L]
#如果没有,则检查其.php等效项是否存在
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则(+)/?$$1.php[L]
#否则,将请求发送到query.php
重写cond%{REQUEST_FILENAME}-F
重写规则(.*)/?$/query.php?$1[L]
根据最后一条规则,如果/testing.php
不存在,在query.php
中使用var\u集水坑($\u GET)
时,请求/testing
应该会导致以下转储:
array(1){[“testing”]=>string(0)“}
试试下面的规则
谢谢-根据我的要求,这是正确的,因此标记为正确。我并没有要求它确保[domain]/显示索引页而不是查询页……我会找出这一部分。Rockett的答案很好。以下是确保/route to index.php的额外步骤:将/route to index.php RewriteCond%{REQUEST_URI}^/$RewriteRule^(.*)$/index.php[L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/query\.php
RewriteRule ^(.*)$ /query.php?$1 [L,R]