gpt4 book ai didi

javascript - 使用 .htaccess 重定向 css|js|img|fonts 文件夹

转载 作者:行者123 更新时间:2023-11-30 11:30:21 24 4
gpt4 key购买 nike

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

我必须通过将 ZendFramework2 添加到根目录(目录名称 = 站点)中来移动此服务器上的 ZendFramework2。 Controller 和操作工作正常,但我无法加载任何 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 以加载/site/public/css/global.css 吗?

当然,我可以改变...

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

...但我不想更改 href

非常欢迎任何帮助!

最佳答案

我只会创建一个 .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]

关于javascript - 使用 .htaccess 重定向 css|js|img|fonts 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46473129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com