简体   繁体   English

htaccess wordpress https重写规则

[英]htaccess wordpress https rewrite rule

I am hoping that you can help me with the htaccess rewrite rule below. 我希望您可以通过下面的htaccess重写规则为我提供帮助。

# BEGIN WordPress

 # WPhtc: Begin Custom htaccess
 # BEGIN WordPress
 <IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{SERVER_PORT} !^443$
 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

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

 # END WordPress

I have recently changed my wordpress site from http to https... The problem is that old url's redirect to the domain name instead of the https version of that page 我最近将我的wordpress网站从http更改为https ...问题是旧网址重定向到域名,而不是该页面的https版本

eg 例如

if I access the following page https://domain.com/test/testing/ it works 100%, now if I change the https part to http then the page redirects to https://domain.com instead of to https://domain.com/test/testing/ how do I fix it so that if you go to the old version page http://domain.com/test/testing/ (the not https version) that it redirects to https://domain.com/test/testing/ instead of just the domain name https://domain.com 如果我访问以下页面https://domain.com/test/testing/它可以100%工作,现在,如果我将https部分更改为http则该页面将重定向到https://domain.com而不是https://domain.com/test/testing/如何修复它,以便如果您转到旧版本页面http://domain.com/test/testing/ (不是https版本),它将重定向到https://domain.com/test/testing/而不只是域名https://domain.com

You have to find a workaround for %{REQUEST_FILENAME} since this only represents the file that is accessed. 您必须找到%{REQUEST_FILENAME}的变通办法,因为这仅代表所访问的文件。 But you obviously want to access the SSL vHost. 但是您显然想访问SSL vHost。 So you might hardcode the https into your .htaccess. 因此,您可以将https硬编码到您的.htaccess文件中。

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This might help you alot. 可能对您有很大帮助。 (found the code above there) (在上面找到了代码)

I've been struggling also with this issue and finally I found a solution for the home redirection and the wordpress in the same htaccess file, and finally it also works for old http links, redirecting to https: 我也在这个问题上苦苦挣扎,最后我在同一个htaccess文件中找到了首页重定向和wordpress的解决方案,最后它还适用于旧的http链接,重定向到https:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# 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

I tried your solution. 我尝试了您的解决方案。 It worked well, but if you do that you'll need to manually change all your internal links. 效果很好,但是如果这样做,则需要手动更改所有内部链接。 This works better ;) 这更好地工作;)

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

I use this .htaccess for wordpress 我将这个.htaccess用于wordpress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM