你真正想要的是“回顾”支持与默认类型。设置你的Apache虚拟主机(东西)是这样的:
<VirtualHost *:80>
ServerName example.com:80
ServerAlias www.example.com
DocumentRoot "/path/to/root/dir"
AddDefaultCharset UTF-8
ErrorDocument 403 "/403.php"
ErrorDocument 404 "/404.php"
<Directory /path/to/root/dir>
Options Indexes FollowSymLinks
DefaultType application/x-httpd-php
AllowOverride All
Order deny,allow
Allow from all
AddOutputFilterByType DEFLATE application/javascript text/css text/html text/plain text/xml
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !.index.ph.*
RewriteRule ^(.*)$ /index.php
</Directory>
</VirtualHost>
的重要行是DefaultType application/x-httpd-php
,这意味着你现在可以摆脱.php
文件扩展名。
您现在可以使用一个URL,如http://example.com/this_is_a_php_page
,您也可以使用http://example.com/this_is_a_php_page/with_a_path_info_var
。
因此,在this_is_a_php_page
(这实际上是一个没有扩展名的.php文件),您可以使用$_SERVER['PATH_INFO']
来检查在URI中传递的变量和变量。
编辑: 添加了RewriteEngine
和规则,推动一切index.php
。这意味着您现在在服务器上有一个名为index.php
的(实际)单个页面,它将需要检查$_SERVER['REDIRECT_URL']
var的真实请求。
例如,对http://example.com/a_page
的请求现在将加载index.php
并将a_page
传递给$_SERVER['REDIRECT_URL']
。注意:这个解决方案会将所有内容都推送到index.php。您将需要包括像一个例外:
RewriteCond %{REQUEST_FILENAME} !.not_me_plz.*
要允许与not_me_plz
文件开头的文件送达“预期”。
好的。所以你的问题是什么!!!!!!!!!!!!!!! –
@mamdouhalramadan问题是我如何“PHP:文件和返回文件路径的搜索目录树” –
在Apache,PHP,Ruby,...什么语言? – Tigger