.htaccess 如何重写某些页面,而不是CSS、JS等?
我自己已经尝试了至少4个小时来解决这个问题,并且已经搜索了数百个堆栈溢出页面和其他论坛来寻找解决方案,但是我似乎无法解决这个简单的问题 内容安排如下:.htaccess 如何重写某些页面,而不是CSS、JS等?,.htaccess,mod-rewrite,rewrite,.htaccess,Mod Rewrite,Rewrite,我自己已经尝试了至少4个小时来解决这个问题,并且已经搜索了数百个堆栈溢出页面和其他论坛来寻找解决方案,但是我似乎无法解决这个简单的问题 内容安排如下: -- index.php -- js - script.js -- css - style.css -- images - image.png <link rel="stylesheet" href="css/style.css" /> 在网站中,我需要将index.php?d
-- index.php
-- js
- script.js
-- css
- style.css
-- images
- image.png
<link rel="stylesheet" href="css/style.css" />
在网站中,我需要将index.php?dept=foo
重写为dept/foo
。这适用于以下规则:
RewriteRule ^dept/(\w+)/?$ index.php?dept=$1 [NC]
但是CSS、JS和图像将不再加载
CSS和JS文件当前包括如下内容:
-- index.php
-- js
- script.js
-- css
- style.css
-- images
- image.png
<link rel="stylesheet" href="css/style.css" />
我尝试将URL更改为具有绝对路径(即/css/style.css
too`,但也没有解决问题)
如何正确解决问题?根据您的评论,有以下重写规则:
RewriteEngine On
RewriteRule ^dept/(\w+)/?$ index.php?dept=$1 [NC,L,QSA]
然后在页面HTML的
部分下方添加以下内容:
<base href="/live/" />
因此,每个相对URL都是从该基本URL解析的,而不是从当前页面的URL解析的
您可以将CSS路径保留为:
<link rel="stylesheet" href="css/style.css" />
style.css的正确和有效URL是什么?@anubhava: