开发者

PHP takes file as a directory?

开发者 https://www.devze.com 2023-03-15 19:16 出处:网络
I have removed the php files extension som my files don\'t have开发者_如何学C the .php, but now some of my PHP code starts to think that it is a directory.

I have removed the php files extension som my files don't have开发者_如何学C the .php, but now some of my PHP code starts to think that it is a directory.

Look at this:

<?php
$currentDir = dirname($_SERVER['SCRIPT_NAME']);
if ($currentDir == '/website/products') {
    echo '<li class="current"><a href="http://localhost/website/products">Products</a></li>';
}
else {
    echo '<li><a href="http://localhost/website/products">Products</a></li>';
}

Then if I have a file within the products folder called example.php then if I type example.php in the adress field it goes in the first one with class="current"

But if i type example in the adress field without the PHP extension, i get in else and don't get the class="current" :( :( :(

Can you help???


One option is add these extensions again and just use mod_rewrite for apache

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
0

精彩评论

暂无评论...
验证码 换一张
取 消