【问题标题】:SSL is breaking my htaccess file in WordPressSSL 正在破坏我在 WordPress 中的 htaccess 文件
【发布时间】:2023-04-11 06:33:01
【问题描述】:

我的 .htacess 文件不仅对重定向很重要,对网站的外观也很重要。我不确定为什么这个主题的开发者会这样做,但我无法改变。

如果您导航到http://akcrossfit.com,您将看到该网站应有的样子。当您导航到 https://akcrossfit.com 时,您会看到没有样式的网站,并且任何导航都会导致 404 错误。

这是我的 .htaccess 文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^other/(.*) /wp-includes/$1 [QSA,L]
RewriteRule ^file/(.*) /wp-content/uploads/$1 [QSA,L]
RewriteRule ^ext/(.*) /wp-content/plugins/$1 [QSA,L]
RewriteRule ^skin/main\.css //index.php?style_wrapper=1 [QSA,L]
RewriteRule ^skin/(.*) /wp-content/themes/richer-child/$1 [QSA,L]
RewriteRule ^richer/(.*) /wp-content/themes/richer/$1 [QSA,L]
RewriteRule ^skin_main/(.*) /wp-content/themes/richer/$1 [QSA,L]
RewriteRule ^ajax /wp-admin/admin-ajax.php [QSA,L]
RewriteRule ^wp-content/themes/richer-child/screenshot\.png|readme \.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

知道要改变什么来解决这个问题吗?该网站托管在 Google Cloud Compute Engine 上。提前感谢您的帮助

这是我的 VHost 配置(至少是与本主题相关的部分)
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName akcrossfit.com:443 DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>

【问题讨论】:

  • 您在访问日志中看到了什么?

标签: wordpress apache .htaccess google-compute-engine


【解决方案1】:

当我尝试通过 https 访问该站点时,它会将我重定向到非 https URL,但我怀疑问题出在Settings &gt;&gt; General 中的 WordPress 地址和站点 URL。

当您查看该站点时,对您的 CSS 和 Javascript 文件的引用将通过 http 链接,这将防止某些浏览器加载不安全的内容。

如果您希望网站安全,请将您的 WordPress 地址更改为 https URL,以便资源和链接使用 SSL。

编辑:在能够通过 https 查看网站后,您的所有资源(js、图像、javascript)似乎都以 404 错误的形式返回。甚至看起来 .htaccess 重写规则不适用于帖子和页面。这很可能是由于 SSL 站点的 VHost 配置错误。 Apache 错误日志可能会有所帮助,但我会先查看 SSL 虚拟主机,看看它与主站点有何不同。

编辑 2:现在的问题是,在您的 &lt;Directory /var/www/&gt; 部分中有 AllowOverride None,它有效地禁用了 .htaccess 重写规则的应用。

【讨论】:

  • 抱歉...我有一个插件正在重定向。网站上只有几个页面需要保护,所以我对保护整个网站不感兴趣。我以前做过,但不是在 Google Cloud 上。
  • @DarrenJackson 我更新了答案,看起来所有站点资源都在 ssl 主机上返回 404 错误。
  • 感谢您的帮助。我今天将对此进行调查并回复您。
  • 我现在的网站首页看起来像它应该的样子 (akcrossfit.com),因为主题不再需要 htaccess 来指向 css 文件。我确定 SSL 正在工作,否则我会在首页上收到 404 错误。但是由于一些奇怪的原因,https 看不到 htaccess 文件,因为当您尝试导航时,所有内部页面都会出现 404 错误。
  • 看起来资源现在正在正确加载,但 .htaccess 文件没有为 ssl vhost 处理。是在虚拟主机上设置了AllowOverride None,还是指定了必要的AllowOverride All?如果为none或未设置,则重写规则和其他指令将被apache忽略。
猜你喜欢
  • 2011-09-05
  • 1970-01-01
  • 2012-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
  • 2012-11-09
相关资源
最近更新 更多