猿问

如何修复不显示CSS的.htaccess重写

我正在Mac上使用本地站点在本地运行localhost,但似乎无法使.htaccess CSS正常工作。我使用的是index.php页面,然后为其提供url变量,以指示要显示的页面(例如index.php?login)。我在这里面临两个问题:第一个是它重定向到不包含我的全局样式的页面,第二个是它显示主页而不是我的登录页面。


我尝试以导航到重写的网站localhost/index.php?login,所有CSS和HTML都显示正常。只有当我重写它时localhost/login,它才会失败。它显示了我的首页,没有任何应包含在index.php中的样式


这是我的.htaccess


<IfModule mod_rewrite.c>


    RewriteEngine On


    RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


DirectoryIndex index.php

RewriteRule ^login$ index.php?login [NC]


</IfModule>

这是我的index.php



//Check for more GET variables.

$url = $_SERVER['REQUEST_URI'];

$split = explode("?", $url);

if (isset($split[1])) {

    $newvarsarray = explode("&", $split[1]);

    foreach ($newvarsarray as $newvar) {

        $keyandvalue = explode("=", $newvar);

        if (isset($keyandvalue[1])) {

            $_GET[$keyandvalue[0]] = $keyandvalue[1];

        } else {

            $_GET[$keyandvalue[0]] = '';

        }


    }

} else {

    //No additional vars, leave $_GET alone.

}



include_once 'globalheader.html';//Imports styles and things

include_once 'header.html';//Stylized header


//This is the area where we handle the different states of the webpage and import them into here

if (empty($_GET)) {

    //Main homepage

    include_once 'mainpage.html';

} else if (isset($_GET['login'])) {

    //Login page

    include_once 'login.html';

} else if (isset($_GET['register'])) {

    //Register page

    include_once 'register.html';

} else if (isset($_GET['profile'])) {

    //Profile page

}


include_once 'footer.html';//Stylized footer

include_once 'globalfooter.html';//Closes things from globalheader.html

?>


我希望它使用正确的CSS显示正确的页面,而不是似乎跳过整个index.php并仅使用.html文件。


狐的传说
浏览 157回答 1
1回答

凤凰求蛊

tl; dr您不见了[OR]。一个文件不能同时“既不是文件也不是目录”。DirectoryIndex index.php<IfModule mod_rewrite.c>&nbsp; &nbsp; RewriteEngine On&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-f [OR]&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-d&nbsp; &nbsp; RewriteRule ^login$ index.php?login [NC]</IfModule>
随时随地看视频慕课网APP
我要回答