Delete get variables and .php using htaccess

吃可爱长大的小学妹 提交于 2019-12-06 21:53:26

Like the comments explain AND the edited Post above, it'll work ;)

but here is another solution i get and works too:

in my document_root i've added a folder called test, in there i've got 4 files with following content:

.htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /test/index.php [L]

index.php - a wrapper for rewrite and testlinks

echo'
<!DOCTYPE html>
    <head>
        <title>Rewrite Test</title>
        <link rel="stylesheet" type="text/css" href="/test/style.css">
    </head>
    <body>
        <a href="/test/home/english">English</a><br>
        <a href="/test/home/francaise">Francaise</a><br>
';
$get = explode("/",$_SERVER["REQUEST_URI"]);
$get = array_slice($get,2); // ignoring first empty key and folder 'test'

#echo "<pre>".print_r($get,true)."</pre>";

if(file_exists($get[0].".php"))
    require($get[0].".php");
else
    echo 'file '.$get[0].'not found';    

echo'
    </body>
</html>';

home.php - as requested

<?php
echo 'in home.php, you have choosen:'.$get[1];
?>

style.css - only as test that file access will work

body {
    color:#ff8800;
    font-weight:bold:
}

tested and works as expected :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!