.htaccess 正在重命名我的 css、img 和 js
.htaccess is renaming my css, img, and js
我正在尝试从 url
路由单个博客 post
url 看起来像这样:http://localhost/news/post/1/post-title-slug
还有我的.htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]`
我的路由文件我目前正在使用一个名为 nezamy/route
的库
$route->get('/post/?/?', function($postid,$page) {
include 'post.php';
});
当我这样做时,我的 css
、js
和 images
也被重命名为如下所示:http://localhost/news/post/1/css/main.css
使用 htaccess 重写时,您需要添加 css/js 文件及其绝对位置。为此,您可以在 php 变量中定义基数 url,如下所示:
$base_url = 'http://localhost/';
然后在你调用 css/js 文件的地方引用它
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>css/main.css">
Prateek 的回答很好,但我通过添加解决了类似的问题。
<base href="/"/>
在我的头上。
或者您可以尝试使用不同的文件夹,例如:
<base href="/web/"/>
等等
我正在尝试从 url
路由单个博客 posturl 看起来像这样:http://localhost/news/post/1/post-title-slug
还有我的.htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]`
我的路由文件我目前正在使用一个名为 nezamy/route
$route->get('/post/?/?', function($postid,$page) {
include 'post.php';
});
当我这样做时,我的 css
、js
和 images
也被重命名为如下所示:http://localhost/news/post/1/css/main.css
使用 htaccess 重写时,您需要添加 css/js 文件及其绝对位置。为此,您可以在 php 变量中定义基数 url,如下所示:
$base_url = 'http://localhost/';
然后在你调用 css/js 文件的地方引用它
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>css/main.css">
Prateek 的回答很好,但我通过添加解决了类似的问题。
<base href="/"/>
在我的头上。
或者您可以尝试使用不同的文件夹,例如:
<base href="/web/"/>
等等