【问题标题】:CSS/JSS loading problem with htaccess URL rewrite使用 htaccess URL 重写的 CSS/JSS 加载问题
【发布时间】:2021-11-05 14:27:51
【问题描述】:

您好,我有一个应用程序应该使用 3 个参数来过滤 url - 模块 / 视图 / Id - 但是,必须添加基本 html 标记来整理 css/jss url 文件,但现在我有一个由于 htacccess 的重定向而导致 css/jss 文件未加载的问题。

Htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Module
RewriteRule ^([^/]+)/?$  index.php?module=$1 [NC,L]

# Module/View
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?module=$1&view=$2 [NC,L]

# Module/View/Id
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?module=$1&view=$2&id=$3 [NC,L]

Options +Indexes
Options +FollowSymlinks

头文件:

<base href="http://localhost/mycbsv2/">
        <!--begin::Fonts-->
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" />
        <!--end::Fonts-->
        <!--begin::Global Stylesheets Bundle(used by all pages)-->
        <link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
        <!--end::Global Stylesheets Bundle-->

问题是,如果您转到 css 文件 url,它不会加载它,因为它正在将文件作为模块搜索(因为 url)...

有没有办法在搜索文件时添加一个例外来不过滤url?

这个问题也可能出现,因为应用程序的所有视图都是从 index.php 文件管理的。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    重写条件仅适用于下一条规则。您有一个重写条件,从您的重写中排除实际文件,但您只为您的三个规则中的第一个设置该例外。您只需要重复每个规则的条件:

    RewriteEngine On
    
    # Module
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$  index.php?module=$1 [NC,L]
    
    # Module/View
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?module=$1&view=$2 [NC,L]
    
    # Module/View/Id
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?module=$1&view=$2&id=$3 [NC,L]
    
    Options +Indexes
    Options +FollowSymlinks
    

    【讨论】:

    • 是的,问题是因为这个 -.-' 感谢您的帮助!真的很感激!
    猜你喜欢
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多