【发布时间】:2021-12-06 08:37:36
【问题描述】:
我正在尝试将 .htaccess 文件中的规则/内容移动到虚拟主机(我的 WordPress 网站的文件)。
服务器详情 - Apache 2.4 on Ubuntu 20.04.3 LTS
这是我移动 .htaccess 文件的内容后虚拟主机文件的样子 -
<IfModule mod_ssl.c>
<VirtualHost *:443>
Protocols h2 http/1.1
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com$1 [L,R=permanent,NC]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<Location />
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN Imagify: webp file type
<IfModule mod_mime.c>
AddType image/webp .webp
</IfModule>
# END Imagify: webp file type
</Location>
</VirtualHost>
</IfModule>
我的查询:-
1. 这样做是否正确?我的意思是,我们可以直接将.htaccess文件的内容粘贴到<Location /> </Location>里面的virtualhost文件/指令中吗?
2. <IfModule mod_rewrite.c> 和 <IfModule mod_mime.c> 在 <IfModule mod_ssl.c> 内部使用。我们可以这样使用它还是我犯了什么错误?
当我检查网站时(重新启动 Apache 服务器后),网站加载没有任何问题,但我想确保我没有做错任何事情。
提前致谢!
【问题讨论】:
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
-
@Community 这个问题很好!?
标签: wordpress apache .htaccess virtualhost apache2.4