我有一个重写规则来从我的网页中删除.php扩展名。它与我在技术上看到的每个样本几乎相同,我尝试过具有相同结果的变体。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
它有效,但我有这种奇怪的异常,我无法理解。
我所有的php文件都存储在根文件夹中,我没有子文件夹。如果我尝试使用子文件夹的网址,我会按预期获得404页面。
但是,如果我使用php脚本名称作为文件夹,我会收到500内部服务器错误。
例如,我有一个名为“logout.php”的脚本
http://example.com/eifiefj/ppp提供了404页
http://example.com/logout/ppp给出500错误??????????????????????
Apache错误日志说......
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
r->uri = /logout/ppp.php.php.php.php.php.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php.php
redirected from r->uri = /logout/ppp.php.php.php
redirected from r->uri = /logout/ppp.php.php
redirected from r->uri = /logout/ppp.php
redirected from r->uri = /logout/ppp
headers: ap_headers_error_filter()
这更像是“我想知道它为什么会发生”的问题。我只是不明白为什么它要继续添加.php,肯定它应该是最后一次RewriteCond失败?
我很想知道这种行为是否会发生在使用删除扩展技术的其他所有人身上。
正如RewriteLog所建议的......
add path info postfix: /var/www/public/logout -> /var/www/public/logout/ppp
strip per-dir prefix: /var/www/public/logout/ppp -> logout/ppp
applying pattern '^(.+)$' to uri 'logout/ppp'
RewriteCond: input='/var/www/public/logout' pattern='!-f' => matched
RewriteCond: input='/var/www/public/logout' pattern='!-d' => matched
RewriteCond: input='/var/www/public/logout.php' pattern='-f' => matched
rewrite 'logout/pod' -> 'logout/ppp.php'
add per-dir prefix: logout/ppp.php -> /var/www/public/logout/ppp.php
strip document_root prefix: /var/www/public/logout/ppp.php -> /logout/ppp.php
internal redirect with /logout/ppp.php [INTERNAL REDIRECT]
nb The log then basically repeats itself adding .php to the end of the filename
似乎REQUEST_FILENAME包含“/ var / www / public / logout”,我可以看到添加php扩展名将匹配最终规则。当然REQUEST_FILENAME应该是“/ var / www / public / logout / ppp”?为什么我会丢失/ ppp?
答案 0 :(得分:1)
虽然实际上没有回答RewriteCond失败的原因,但我发现了一套实际上克服了文件夹/脚本问题的规则。我在这里重现它,以帮助任何寻求功能脚本的人。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(([^/]*/)*[^.]+)$ /$1.php
此RewriteRule仅适用于名称不包含句号的文件,即没有扩展名的文件。