0

i want help in this problem

this command not work good can u help me

i have new folder on my website under this name

"TextPHP"

and i put this code in .htaccess

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

i want any one go to that folder can read any source from my php files

and this not work

i try H=text/plain

and i got error 500

also i try php_value engine off php_value engine off

not working :(

its there any other trick

and sorry about my english language so bad :p

thanks for helping

VegaQ8
  • 1
  • 1

2 Answers2

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.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • also not work :( my site example.com and i have many php files on it i want if one access to example.com/source/FileName.php read source for example.com/FileName.php as text file – VegaQ8 Feb 19 '13 at 01:46
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
mario
  • 144,265
  • 20
  • 237
  • 291
  • see my site http://example.com/ and i have over 400 php file on this site i want every one enter to http://example.com/source/FileName.php read source of http://example.com/FileName.php – VegaQ8 Feb 19 '13 at 01:44
  • Then you'll need said wrapper script, see http://stackoverflow.com/questions/10693873/php-show-source-code-instead-of-html-file for an example. The `basename()` thing is super crucial! – mario Feb 19 '13 at 01:49