Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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
Javascript Nginx重写错误,在index.php中包含文件_Javascript_Css_.htaccess_Nginx_Relative Path - Fatal编程技术网

Javascript Nginx重写错误,在index.php中包含文件

Javascript Nginx重写错误,在index.php中包含文件,javascript,css,.htaccess,nginx,relative-path,Javascript,Css,.htaccess,Nginx,Relative Path,我有一个apache Web服务器,在那里我只需要一个htaccess。我切换到NGINX,并进行了NGINX配置。我的重写如下: location /mvc/public { index index.php; try_files $uri $uri/ @rewrite; } location @rewrite{ rewrite ^/mvc/public/(.*)$ /mvc/public/index.php?url=$1; } 这可以正常工作,但是现在我想

我有一个apache Web服务器,在那里我只需要一个htaccess。我切换到NGINX,并进行了NGINX配置。我的重写如下:

location /mvc/public {
     index index.php;

     try_files $uri $uri/ @rewrite;
 }

location @rewrite{
     rewrite ^/mvc/public/(.*)$ /mvc/public/index.php?url=$1;
}
这可以正常工作,但是现在我想要包含在我的索引文件中的其他文件,比如css和其他一些脚本,会给出一个错误

我得到的错误是:

GET "example.com"/mvc/public/javascript/show/css/bootstrap.min.css 
GET "example.com"/mvc/public/javascript/show/css/simple-sidebar.css
GET "example.com"/mvc/public/javascript/show/css/custom.css 
GET "example.com"/mvc/public/javascript/show/js/bootstrap.min.js
当我转到“example.com”/mvc/public/javascript/show/examplecode时。css的正确路径是“example.com”/mvc/public/css,js是“example.com”/mvc/public/js

我在Apache中使用的HTACCESS是:

Options -MultiViews
RewriteEngine On

RewriteBase /mvc/public

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

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

所以我的问题是,我如何让它工作,我做错了什么?

这看起来根本不像是重写问题。看起来您的页面链接中有相对URL。当您转到:

/mvc/public/javascript/show/examplecode
相对的URL基础是
/mvc/public/javascript/show/
,因此当您使用css时,如:

<link rel="stylesheet" href="css/custom.css" type="text/css">
因此,您需要将所有链接更改为绝对URL,或者在页面标题中添加一个基(在
中):


/mvc/public/javascript/show/css/custom.css 
<base href="/mvc/public/" />