wordpress - 主目录 HTML 和子目录 WordPress 网站上的非 www 到 www 重定向不起作用
问题描述
我有一个在主域上运行的 HTML 网站,我通过在主目录的.htaccesshttp://arabyouthsurvey.com
上添加一些代码,在其上添加了非 www 到 www 重定向。现在我在子目录中有一个 WordPress 博客,例如.http://arabyouthsurvey.com/media-center
首先,我需要重定向所有非 www 的 URL,包括我的博客应该用 www 重定向。
我面临的问题是:
如果我在主目录的 .htaccess 上添加重定向。它仅重定向 HTML 网站的 URL,但是,它阻止了我博客上的网络字体。
在主 .htaccess 文件上添加重定向后,我在博客中遇到了这个错误
Access to Font at 'http://www.arabyouthsurvey.com/assets/fonts/karbon-regular-webfont.woff2' from origin 'http://arabyouthsurvey.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://arabyouthsurvey.com' is therefore not allowed access.
如果我也在我的博客 .htaccess 文件中添加重定向。它不工作。
这是我在主目录 .htaccess 文件中添加的代码
ErrorDocument 404 http://arabyouthsurvey.com/page404.html
# redirect non www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
这是我的 WordPress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /media-center/
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
解决方案
推荐阅读
- oracle - 使用多个类似条件使用另一个表中的值更新一个巨大的表
- jenkins - 是的,我可以在 jenkins 中启动一个守护进程。但是如何重新启动守护进程呢?@视窗
- sql-server - 如何在一个查询中清除所有系统版本表?
- python - 如何根据熊猫中的多列条件删除行?
- c - 如何为 Glade 的 GTK 按钮分配命令?
- mysql - 我的更新查询有语法错误
- r - 如何使用 qcc 在 EWMA 控制图中绘制多个控制限?
- python - 如何使用 python 从图像中去除污渍?
- spring - 通过 Spring data elasticsearch repo 保存到 ElasticSearch 后 LocalTime(00:01:002) 变为 (24:00:02)
- c - 为什么insertBeg没有在开头插入节点