为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
狐的传说 2021-04-09 13:15:49
我正在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} !-fRewriteCond %{REQUEST_FILENAME} !-dDirectoryIndex index.phpRewriteRule ^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 thingsinclude_once 'header.html';//Stylized header//This is the area where we handle the different states of the webpage and import them into hereif (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 footerinclude_once 'globalfooter.html';//Closes things from globalheader.html?>我希望它使用正确的CSS显示正确的页面,而不是似乎跳过整个index.php并仅使用.html文件。
查看完整描述

1 回答

?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

tl; dr您不见了[OR]。


一个文件不能同时“既不是文件也不是目录”。


DirectoryIndex index.php


<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f [OR]

    RewriteCond %{REQUEST_FILENAME} !-d

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

</IfModule>


查看完整回答
反对 回复 2021-04-23
  • 1 回答
  • 0 关注
  • 156 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信