Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.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 使用.htaccess重定向css | js | img |字体文件夹_Javascript_Css_.htaccess_Zend Framework2 - Fatal编程技术网

Javascript 使用.htaccess重定向css | js | img |字体文件夹

Javascript 使用.htaccess重定向css | js | img |字体文件夹,javascript,css,.htaccess,zend-framework2,Javascript,Css,.htaccess,Zend Framework2,我在一些网站所在的共享主机上 我必须通过将ZendFramework2从根目录(dir name=site)添加到一个目录中来移动该服务器上的ZendFramework2。控制器和操作正常,但我无法加载任何css、图像或javascript 以下是我的目录: /root/website1 (example.com/website1) /root/website2 (example.com/website2) /root/site (example.com/site) /root/site

我在一些网站所在的共享主机上

我必须通过将ZendFramework2从根目录(dir name=site)添加到一个目录中来移动该服务器上的ZendFramework2。控制器和操作正常,但我无法加载任何css、图像或javascript

以下是我的目录:

/root/website1 (example.com/website1)
/root/website2 (example.com/website2)
/root/site     (example.com/site)
/root/site/application
/root/site/data
/root/site/library
/root/site/public
/root/site/public/css
/root/site/public/fonts
/root/site/public/img
/root/site/public/js
/root/site/public/.htaccess
/root/site/.htaccess
.htacces位于/site文件夹中

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /site/public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/site/public/.*$
RewriteRule ^(.*)$ /site/public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^site/public/.*$ /site/public/index.php [NC,L]
.htacces位于/site/public文件夹中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /site/index.php [NC,L]
css标签:

<link href="/css/global.css" rel="stylesheet" type="text/css" media="screen" />

我可以将/css/global.css重定向到load/site/public/css/global.css吗

当然,我可以换

<link href="/site/css/global.css" rel="stylesheet" type="text/css" media="screen" />

。。。但我不想改变


欢迎任何帮助

我只创建一个.htaccess文件来解决您的所有问题。请将此文件放入/root文件夹并删除其他.htaccess文件

# This first part should be done by the webserver,
# if not than thing about to change you hoster but I put it here:
# Preventing direct access to any .ht file (.htaccess, .htpasswd, etc.)
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

Options +FollowSymlinks
Options -Indexes

# Start to Rewrite
RewriteEngine On

# For all URL starting with /css, /fonts, /img or /js
RewriteCond %{REQUEST_URI} ^/?(css|fonts|img|js)(/.*)?$ [NC]
RewriteRule ^.*$ /site/public/%1%2 [L]

# Redirect all to the Application if not done already
RewriteCond %{REQUEST_URI} !^/?site/public/index\.php [NC]
# but not if the URL starts with css, fonts, img or js
RewriteCond %{REQUEST_URI} !^/?(css|fonts|img|js)(/.*)?$ [NC]
# or if request is a real file
RewriteCond %{REQUEST_FILENAME} !-f
# or if request is a real directory but not the root directory
RewriteCond %{REQUEST_URI} ^/?$ [OR]
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite the rest to the index.php file in your public folder
RewriteRule ^.*$ /site/public/index.php [NC,L]
#第一部分应该由Web服务器完成,
#如果不是比事情要改变你主人,但我把它放在这里:
#阻止直接访问任何.ht文件(.htaccess、.htpasswd等)
要求全部拒绝
选项+FollowSymlinks
选项-索引
#开始重写
重新启动发动机
#对于所有以/css、/font、/img或/js开头的URL
重写条件%{REQUEST_URI}^/?(css |字体| img | js)(/.*)$[NC]
重写规则^.*$/site/public/%1%2[L]
#如果尚未完成,则将所有内容重定向到应用程序
重写条件%{REQUEST_URI}!^/?site/public/index\.php[NC]
#但如果URL以css、字体、img或js开头,则不会
重写条件%{REQUEST_URI}!^/?(css |字体| img | js)(/.*)$[NC]
#或者如果请求是真实的文件
重写cond%{REQUEST_FILENAME}-F
#或者如果请求是真实目录,但不是根目录
重写条件%{REQUEST_URI}^/?$[或]
重写cond%{REQUEST_FILENAME}-D
#将其余部分重写到公用文件夹中的index.php文件中
重写规则^.*$/site/public/index.php[NC,L]

对不起,我弄糊涂了。如果您将您的网站命名为/root或/root/site或/root/site/public,那么什么是公共目录?公共目录仅用于保护。用户必须看到的一切都在那里(图像、脚本、css、字体)。所有不公开的内容都是受目录级别保护的服务器端代码和配置。是的,我知道这一点,但这并不能回答我的问题,如果/root/site/public将是您真正的公用文件夹,那么example.com/css/global.css将显示css,但因为不是这样,您的根目录是什么?它是/root还是/root/site/root实际上是apachehtdocs,每个网站目录都位于其中。因此,/root/中没有任何内容。站点的文档根必须是/root/site,example.com/site/css/global.css是我目前正在寻找的,我只对您的宿主如何配置您的Web空间感兴趣。如果您要从Web空间中删除所有文件并在浏览器中调用您的网站,那么文档的根目录是什么?你会得到/root或/root/site的内容吗。因为您的第一个.htaccess文件位于/root/site中,所以我假设您的文档是root/root/site,而不是/root。如果是这种情况,我们就不必关心/site文件夹,而只关心/public。如果不是的话,我想知道如果你在/root.com中没有.htaccess文件,你将如何被重定向到公用文件夹中的index.php文件,这使得工作!!!非常感谢你抽出时间,我真的很感激