wordpress - Creating the most efficient .htaccess file
问题描述
I have been asked to clean up a htaccess file.
Here is the current code:
RewriteOptions inherit
# This file was updated by Duplicator on 2018-05-01 07:23:35. See .htaccess.orig for the original .htaccess file.
# Please note that other plugins and resources write to this file. If the time-stamp above is different
# than the current time-stamp on the file system then another resource has updated this file.
# Duplicator only writes to this file once during the install process while running the installer.php file.
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token, User-Agent, Content-Disposition"
Header always set Access-Control-Expose-Headers "Content-Disposition"
# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# RewriteCond %{HTTPS} off
# RewriteCond %{HTTP:X-Forwarded-SSL} off
# RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
# RewriteCond %{HTTP_HOST} ^www\.example\.com$
# RewriteRule ^(.*)$ "https\:\/\/www\.example\.com\/$1" [R=301,L]
# RewriteEngine On
# RewriteCond %{HTTP_HOST} ^example.com/com [NC]
# RewriteCond %{SERVER_PORT} 80
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
A couple points:
In my SEO report it states 'No redirect or canonical to HTTPS homepage from HTTP version'.
~ even though I have a declaration in my header file that sets the canonical link, also the htaccess file currently redirects to the https version.
~ Apparently a 301 redirect will fix the above issue - from what I have read.
~ This is the reason I have been asked to look into this file.
I wish for the site to redirect to the https version.
I wish to keep the local caching of images.
Feel free to remove commented out lines if this doesn't help
What is the best practice to achieve the results I currently am getting but so it uses a '301 redirect' with less clutter in the code?
Any help / advice you can provide would be great!
Thanks, Jason.
解决方案
推荐阅读
- grep - grep 可以同时显示计数和匹配项吗?
- python - FastAPI - Pydantic - 值错误引发内部服务器错误
- php - PHP 7.4.21 警告:count():参数必须是数组或实现 Countable 的对象
- amazon-web-services - 使用 AWS API Gateway 下载 .MSI 文件
- google-drive-api - 访问链接共享文件的 GDrive API 端点调用和安全更改
- json - 如何在 VB.net 中使用类似的 VBA 代码?(
- swift - 如何将 OperationQueue 与异步函数一起使用?
- c++ - 通过为 DPI-C 混合 C 和 C++ 生成 .so 文件
- python - 在 pandas 中创建子标题的问题
- nosql - 从 lmdb 数据库返回 Form B-Tree