0

我想帮助解决这个问题

这个命令不好用,你能帮帮我吗

我的网站上有这个名称的新文件夹

“文本PHP”

我把这段代码放在.htaccess

RewriteRule ^(.*) /home/myhome/public_html/$1.php [L,T=text/plain]

我希望任何人进入该文件夹都可以从我的 php 文件中读取任何源

这行不通

我尝试 H=text/plain

我收到错误 500

我也尝试关闭 php_value 引擎 php_value 引擎关闭

不工作:(

它还有其他技巧吗

对不起我的英语太糟糕了:p

谢谢你的帮助

4

2 回答 2

0

You don't specify the full path to the file in the rewrite rule, what you are specifiying is a new absolute URL or a URI relative to the web root. So if you want to make any URI go to a PHP file of teh same name, here is how you would do it:

RewriteEngine On
RewriteRule ^(.*) /$1.php [L]

No need to specify /home/myhome/public_html here.

This is a basic example however, as typically, this is much too broad of a rule, as it would prevent you from serving up images or other actual files from the web root (they would all end up with .php appended to the. So assuming this is actually what you want, you would commonly see something like:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /$1.php [L]

This rule applies in cases when the URI does not match an actual filename or directory. Thus requests to /some_file.php would not be redirected to /some_file.php.php.

于 2013-02-19T01:40:35.877 回答
0

You can configure your webserver to show the source for *.phps files (e.g. make symlinks) with:

AddType application/x-httpd-php-source .phps

Or to disable PHP processing for that directory completely use:

RemoveHandler .php 
RemoveType .php

Alternatively or additionally with:

php_flag engine off

On some setups (cgi / fastcgi) even:

Options -ExecCGI

If you wanna use mod_rewrite, then write a wrapper script for displaying them via readfile() (and some basename() filtering for security) and apply it like:

RewriteRule ^(.+\.php)$ showsrc.php?file=$1
于 2013-02-19T01:40:43.380 回答