Magento 2.4.1-网站已移至子目录-CSS&JS损坏-已清除缓存仍然损坏[已解决] [英] Magento 2.4.1 - Moved site to a subdirectory - CSS & JS Broken - cleared Cache still broken [SOLVED]
问题描述
我正在尝试找出在Cpanel服务器上安装Magento 2.4.2的一些问题.我安装了2.4.1,以查看是否可以正常使用.我将其移到一个子目录中以确保可以执行此操作,并且遇到了CSS/JS损坏的常见错误.
I'm in the process of trying to figure out some issues with Magento 2.4.2 installation on a Cpanel server. I installed 2.4.1 to see if that would work and it still does. I moved it into a subdirectory to make sure I could do that and I got the usual error that the CSS/JS broke.
我登录了管理员,并从以下位置设置了基本网址:
I logged into the admin and set the base url from:
http://www.fieldhockey.co/
也是:
http://www.fieldhockey.co/store/
并保存了表单,我被重定向到了新位置,但是它显然坏了.我转到根文件夹,然后将所有Magento代码和目录拖到新的子目录中,并且CSS/JS仍然损坏(无法加载).
And saved the form, I got redirected to the new location but its obviously broken. I go to the root folder and drag all the Magento code and directories into my new sub-directory and the CSS/JS is still broken (not loading).
现在,我读到一篇文章,您应该删除或重命名/pub/static/目录,以便使用新路径重新生成Cache.我尝试了此操作,并创建了目录,但无法解决问题.
Now I read in an article that you should delete or rename the /pub/static/ directory so the Cache is regenerated using the new path. I tried this and the directory was created but it did not fix the issue.
我不确定该如何解决?
推荐答案
在比较2个目录(我将其重命名)时,我注意到/var/static2/目录包含一个.htaccess文件,而我新创建的目录没有.将.htaccess移到新的静态目录后,我的问题已解决.
On comparing the 2 directories (I renamed it) I noticed the /var/static2/ directory contained a .htaccess file which my newly created directory did not. Upon moving the .htaccess to the new static directory my issue was fixed.
希望这将对有此问题的其他人有所帮助-因为.htaccess文件似乎不会自动通过目录重新生成?
Hopefully this will help someone else who has this issue - as the .htaccess file does not seem to be regenerated with the directory automatically?
.htaccess的副本(版本2.4.1)
Copy of the .htaccess (version 2.4.1)
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
<IfModule mod_php7.c>
php_flag engine 0
</IfModule>
# To avoid situation when web server automatically adds extension to path
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
## you can put here your pub/static folder path relative to web root
#RewriteBase /magento/pub/static/
# Remove signature of the static files that is used to overcome the browser cache
RewriteRule ^version.+?/(.+)$ $1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* ../static.php?resource=$0 [L]
# Detects if moxieplayer request with uri params and redirects to uri without params
<Files moxieplayer.swf>
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
</Files>
</IfModule>
############################################
## setting MIME types
# JavaScript
AddType application/javascript js jsonp
AddType application/json json
# HTML
AddType text/html html
# CSS
AddType text/css css
# Images and icons
AddType image/x-icon ico
AddType image/gif gif
AddType image/png png
AddType image/jpeg jpg
AddType image/jpeg jpeg
# SVG
AddType image/svg+xml svg
# Fonts
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf
AddType application/x-font-otf otf
AddType application/x-font-woff woff
AddType application/font-woff2 woff2
# Flash
AddType application/x-shockwave-flash swf
# Archives and exports
AddType application/zip gzip
AddType application/x-gzip gz gzip
AddType application/x-bzip2 bz2
AddType text/csv csv
AddType application/xml xml
<IfModule mod_headers.c>
<FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$>
Header append Cache-Control public
</FilesMatch>
<FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$>
Header append Cache-Control no-store
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresActive On
# Data
<FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$>
ExpiresDefault "access plus 0 seconds"
</FilesMatch>
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType text/csv "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/zip "access plus 0 seconds"
ExpiresByType application/x-gzip "access plus 0 seconds"
ExpiresByType application/x-bzip2 "access plus 0 seconds"
# CSS, JavaScript, html
<FilesMatch \.(css|js|html|json)$>
ExpiresDefault "access plus 1 year"
</FilesMatch>
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/html "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/json "access plus 1 year"
# Favicon, images, flash
<FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>
ExpiresDefault "access plus 1 year"
</FilesMatch>
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
# Fonts
<FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$>
ExpiresDefault "access plus 1 year"
</FilesMatch>
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-otf "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
这篇关于Magento 2.4.1-网站已移至子目录-CSS&JS损坏-已清除缓存仍然损坏[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!