apache - same file with .php and without .php without any mod_rewrite RewriteRule
I have installed a Apache (on ubuntu) with some vhosts. In the www-dirs I have a file (for example) called info.php. And I can open this file by /info.php AND /info (without the .php at the end).
There is no mod_rewrite rule in the Vhost or the dir.
And if I try a rewrite rule like:
RewriteRule ^info$ http://www.google.com/ [R=307,L]
and reopen /info (without the .php) it dosn't work.
When I change the role to
RewriteRule ^info.php$ http://www.google.com/ [R=307,L]
and reopen the /info it works.
And when I try this rule:
RewriteRule ^(.*)$ echo.php?value=$1 [L]
and open a site like /foo and print the $value I get "echo.php". When I try /foo/bar I get "echo.php/bar"
Does anyone have a tip for me?
Add: Here are some information from the phpinfo():
SCRIPT_FILENAME /var/www/test/echo.php
QUERY_STRING value=echo.php
REQUEST_URI /foo
SCRIPT_NAME /echo.php
Answer
Solution:
You need a
RewriteCond
before yourRewriteRule
that matches the base case where no rewriting should occur. Otherwise your redirected request will also be rewritten.Answer
Solution:
The dollar sign marks the end of a string. You could use (untested):
Answer
Solution:
Being able to access files without needing to write extensions is caused by MultiViews options in Apache. To disable it, use:
You can try turning it off and see if it works or not.
Alternatively, for your
echo.php
, you can just use:And then have
echo.php
check fromREQUEST_URI
which contains the path that is originally requested.