duanao4729 2019-04-15 13:32
浏览 155
已采纳

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

This question already has an answer here:

I'm running a localhost on my Mac using the native sites, and I can't seem to get .htaccess CSS working. I'm using an index.php page, that is then given url variables to tell which page to display (ex. index.php?login). There two issues I'm facing here: The first is that it redirects to a page where my global styles aren't included, and the second is that it shows the homepage instead of my login page.

I've tried navigating to the rewritten site as localhost/index.php?login, and all the CSS and HTML displays fine. It's only when I rewrite it as localhost/login that it fails. It shows my homepage without any of the styles that should be include from index.php

Here is my .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>

Here is my 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
?>

I want it to display the correct page with correct CSS instead of seemingly skipping over the entirety of index.php and just using the .html file.

</div>
  • 写回答

1条回答 默认 最新

  • doudai3012 2019-04-15 13:36
    关注

    tl;dr you are missing [OR].

    A file cannot be "not a file nor a directory" at the same time.

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line