Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess重写条件不工作_Php_Apache_.htaccess - Fatal编程技术网

Php htaccess重写条件不工作

Php htaccess重写条件不工作,php,apache,.htaccess,Php,Apache,.htaccess,我希望你能帮忙。我正在尝试编写一个htaccess文件,请执行以下操作 1) 重定向到www.address 2) 从url中删除.php 3) 如果文件不存在,则使用filechecker.php?page=filename 1.我能忍受 RewriteCond%{HTTP_HOST}^example.com$ 重写规则(.*)$1[R=301,L] 2) 我受够了 RewriteCond%{SCRIPT_FILENAME}.php-f 重写规则[^/]$%{REQUEST_URI}.ph

我希望你能帮忙。我正在尝试编写一个htaccess文件,请执行以下操作

1) 重定向到www.address

2) 从url中删除.php

3) 如果文件不存在,则使用filechecker.php?page=filename


1.我能忍受

RewriteCond%{HTTP_HOST}^example.com$

重写规则(.*)$1[R=301,L]


2) 我受够了

RewriteCond%{SCRIPT_FILENAME}.php-f

重写规则[^/]$%{REQUEST_URI}.php[QSA,L]


3) 我想

重写cond%{REQUEST_FILENAME}.php-f

重写规则^([^/]*)$filechecker.php?页面=$1[QSA,L]

这样做是可行的,但出于某种原因,它忽略了页面确实存在的事实


我希望你能帮忙
标记

第2部分和第3部分的解决方案将循环,但非常简单,可以修复,在文件中沿以下行粘贴一些内容:

#If the Browser request contains a .php, instruct the browser to remove it.
RewriteCond %{THE_REQUEST}      \.php      [NC]
RewriteRule ^/?(.*)\.php$       http://%{HTTP_HOST}/$1         [R=301,NC,L]

#If a request is received for a non file-system object, that doesn't have a .php suffix, then store the full path, filename, and URI in a variables with that extention.
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-s
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !^\.php$  [NC]
RewriteRule ([^/]+)$      -  [E=testScript:%{SCRIPT_FILENAME}.php,E=testFile:$1.php,E=testURI:%{REQUEST_URI}.php]

#See if the file exists with a .php extention, if it does internally rewrite
RewriteCond %{ENV:testScript} -s  [OR]
RewriteCond %{ENV:testScript} -f
RewriteRule .*              %{ENV:testURI} [L]

#Else if a ENV:testDile is set, then pass the name to the php script
RewriteCond %{ENV:testFile} !^$
RewriteRule .*               /filechecker.php?page=%{ENV:testFile} [L]

FY: Apache文档值得一读,如果你不清楚上面的规则是怎么做的,或者如果你想要一些更抽象的东西,请考虑下面的内容。p>