Reputation: 1601
I'm writing a basic little CMS and use RewriteRules to redirect each request to index.php wich then parses the rest of the URI and requires/includes different php files to put together the requested site. The Rewriting and the parsing of the URI seem to work just fine, however when I try to include a php file all the output of index.php is erased and ONLY the output of the included php file is shown.
I wrote a basic script to test the problem but I can't find the problem:
The index.php
<?php
if(isset($_GET['parameter_1']))
$get_parameter_1 = $_GET['parameter_1'];
if(isset($get_parameter_1))
{
echo "You favourite colour is ";
if($get_parameter_1 == "red")
{
include('red.php');
}
else
{
echo "obviously not red.";
}
}
else
{
echo "
Parameter not set.
";
}
?>
The red.php
<?php
echo "red";
?>
The .htaccess
RewriteEngine on
RewriteBase /htaccess_testing/
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
RewriteRule \.(php)$ - [L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/htaccess_testing/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /htaccess_testing/index.php?parameter_1=$1 [L]
When I request www.example.com/htaccess_testing/ it correctly shows "Parameter not set."
When I request www.example.com/htaccess_texting/blue/ it correctly shows "Your favourite colour is obviously not red."
When I request www.example.com/htaccess_testing/red/ it only shows "red." instead of "your favourite colours is red." wich is what it should do...
Can anybody point out my mistake? Thank you /K
Upvotes: 0
Views: 1090
Reputation: 255115
That happens because you have specified the condition
RewriteCond %{REQUEST_FILENAME} !-f
It means: don't rewrite if file exists. Just remove it
UPD:
You need to put
Options -MultiViews
in the beginning of your .htaccess
Upvotes: 1