Sự cố với chuyển hướng trong htaccess wordpress

Aug 02 2019

Tôi có các chuyển hướng sau trong htaccess. Wordpress được cài đặt trong thư mục home Trang web phải chuyển hướng một example.com (không có www) và với https. Cài đặt wordpress trong / home

Và tôi không biết làm thế nào để sửa chữa nó. Bất kỳ đề xuất? Cảm ơn bạn !!

RewriteCond %{HTTP_HOST} ^example.com$ RewriteCond %{REQUEST_URI} !^/home/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /home/$1 RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(/)?$ home/index.php [L] # BEGIN SSL <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^example\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>

 # END SSL```

Trả lời

2 RohitKaushik Aug 02 2019 at 17:40

Bạn không thể buộc thư mục con hoặc tên miền phụ chuyển hướng đến https

để chuyển hướng https, chỉ cần sử dụng cái này

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Đối với Thư mục con

RewriteRule ^/?(.*) https://%{SERVER_NAME}/home/$1 [R,L]

bạn cũng có thể sử dụng .htaccess mặc định để chuyển hướng

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>