首页 > 解决方案 > 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:

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.

标签: wordpress.htaccess

解决方案


推荐阅读