1

I want to rewrite my url from php extention to html.and if that file was not found then it should redirect to some custome page(404.php).

I have written rule like this:

RewriteEngine on
RewriteRule ^$ front/index.php?query=$1 [NC,L,QSA]
RewriteRule (.*)\.(html) ?page=$1 [L,NC,QSA]
ErrorDocument    404    /expertLocal/?page=404

using this i am facing problem like this. http://somedomain.com/expertLocal/contact.html

it will work file coz i have contact.php page . if i will write somedomain.com/expertLocal/contactxyz.php then it redirect to 404.php page but if i will write http://somedomain.com/expertLocal/contactxyz.html in address bar then it will give warnings instead of 404.php page.

This is because i ahve used my own framework and in this structure file is first redirect to controller index file and then included requested file there.

include(FRONT_CONTROLLER_PATH . $page . '.php');   like this.

Can you please help me out?

Thanks in advance..

4

1 に答える 1

0

フレームワークについてはわかりませんが、以下のコードが役立つかどうかを確認してください。

$filename = FRONT_CONTROLLER_PATH . $page . '.php';
if (file_exists($filename)) 
{
       include($filename); 
}
else
{
       // include 404 page here
}
于 2012-07-11T05:22:59.017 に答える