【问题标题】:pretty url static files not loading漂亮的 url 静态文件未加载
【发布时间】:2021-01-03 20:31:44
【问题描述】:

我正在构建一个社交网络,而我的 htaccess 漂亮 url 没有加载 css/js/img/php 文件。以下规则有效

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^login$ index.php?act=login [NC]
RewriteRule ^register$ index.php?act=register [NC]
RewriteRule ^forgot$ index.php?act=forgot [NC]

但以下规则有效,但不加载 css/js/img

RewriteRule ^user/(\w+)/?$ index.php?act=profile&user=$1 [NC]

我做错了什么?我没有设置基本网址。主页网址是

http://localhost/myWebsite/source/

我的控制器中还有以下逻辑,包含在索引页面的顶部

    if ($isLogged == true) {
        // check if page request set
        if (isset($_GET['act'])) {
            // valid pages
            $pgeArray = array("stories", "hashtags", "media", "user", "search");
            // check if page is valid
            if (in_array($_GET['act'], $pgeArray)) {
                // get page name request
                $pgeReq = $_GET['act'];
            }else {
                // show registration page
                $pgeReq = "home";
            }
        }else {
            // show registration page
            $pgeReq = "home";
        }
    }
    else {
        // check if page request set
        if (isset($_GET['act'])) {
            // valid pages
            $pgeArray = array("register", "login", "forgot");
            // check if page is valid
            if (in_array($_GET['act'], $pgeArray)) {
                // get page name request
                $pgeReq = $_GET['act'];
            }else {
                // show registration page
                $pgeReq = "login";
            }
        }else {
            // show registration page
            $pgeReq = "login";
        }

    }

【问题讨论】:

  • 那么,这些 css 和 js 文件实际加载的 URL 是什么,它们被重写为什么? 声称它们被重写...
  • 工作3将在source/之后添加漂亮的url,例如source/login
  • 要么对 css/js 使用绝对路径,要么在 HTML 中使用 <base...> 标签
  • 是的,这样一个更简单的解决方案,谢谢

标签: php apache .htaccess


【解决方案1】:

我所要做的就是指定一个基本网址<base href="http://localhost/myWebsite/source/" /> `

【讨论】:

    猜你喜欢
    • 2016-11-07
    • 2021-01-12
    • 2021-05-28
    • 2012-05-28
    • 2019-08-31
    • 2014-11-12
    • 2021-04-03
    • 2012-01-21
    • 2016-11-06
    相关资源
    最近更新 更多