创建最有效的.htaccess文件

时间:2019-01-03 09:58:05

标签: wordpress .htaccess

已要求我清理htaccess文件。

这是当前代码:

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]

几点:

  • 在我的SEO报告中,它声明“从HTTP版本到HTTPS主页均未重定向或规范”。

    〜即使我的头文件中有一个设置规范链接的声明,htaccess文件当前也重定向到https版本。

    〜显然301重定向可以解决上述问题-根据我的阅读。

    〜这就是要求我查看此文件的原因。

  • 我希望网站重定向到https版本。

  • 我希望保留图像的本地缓存。

  • 如果这样做没有帮助,请随时删除注释掉的行

什么是实现我目前获得的结果的最佳实践,但是它使用了“ 301重定向”并且代码中的混乱程度更低?

您可以提供的任何帮助/建议都很棒!

谢谢杰森。

0 个答案:

没有答案