Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用.htaccess在localhost上使用绝对css、js和其他路径?_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

如何使用.htaccess在localhost上使用绝对css、js和其他路径?

如何使用.htaccess在localhost上使用绝对css、js和其他路径?,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我的index.php文件具有CSS、JS、图像和字体的绝对路径。像下面这样 <link href="/css/style.css" rel="stylesheet"> <script src="/js/jquery.js"></script>.................many more. 但它们应该链接到这里: http://127.0.0.1/example/css/style.css http://127.0.0.1/example/js/jq

我的index.php文件具有CSS、JS、图像和字体的绝对路径。像下面这样

<link href="/css/style.css" rel="stylesheet">
<script src="/js/jquery.js"></script>.................many more.
但它们应该链接到这里:

http://127.0.0.1/example/css/style.css
http://127.0.0.1/example/js/jquery.js
我在本地.htaccess文件中尝试了以下几行:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/

重新启动发动机
重写基础/示例/

但是css、js、图像和字体仍然指向不正确。

在本地主机上,您可以在
文档中使用此代码。\u ROOT/.htaccess
文件:

RewriteEngine On
RewriteRule ^((?:css|js)/.+)$ /example/$1 [L,NC]

正如你所说,我在我的文件中添加了这些行,但不起作用。不,我写的是在
DOCUMENT_ROOT/.htaccess
文件(示例目录的父目录)中添加它,但我认为在这里添加127.0.0.1/.htaccess将影响我的其他项目..?1。无法通过
/example/.htaccess
对其进行控制。2.它只会影响
/css/
/js/
路径。不管它是否会影响我的其他项目。谢谢你@anubhava
RewriteEngine On
RewriteRule ^((?:css|js)/.+)$ /example/$1 [L,NC]