admin管理员组文章数量:1130349
After implementing ssl on wordpress, I wanted to force a redirection to a site with the following characteristics:
non www, ssl, with trailing slash
Unfortunately it only works in some cases.
For instance, instead of redirecting from a site with these characteristics (http, non www, without trailing slash to https, non www with trailing slash), it redirects like this:
overto/.
I also have an issue with redirecting a www, http site without trailing slash to an https, non www, with trailing slash site.
Currently, it redirects from via to and /.
Therefore my question is: How can I fix this? Is this done somehow by the Wordpress system?
Enclosed you'll find my .htaccess file. I hope you can help me.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)
Could this be somehow caused by WordPress? I've mentioned this before, but there is also a rewrite code from WordPress.
# 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>
After implementing ssl on wordpress, I wanted to force a redirection to a site with the following characteristics:
non www, ssl, with trailing slash
Unfortunately it only works in some cases.
For instance, instead of redirecting from a site with these characteristics (http, non www, without trailing slash to https, non www with trailing slash), it redirects like this:
http://example/foooverhttps://example/footohttps://example/foo/.
I also have an issue with redirecting a www, http site without trailing slash to an https, non www, with trailing slash site.
Currently, it redirects from http://www.example/foo via http://example/foo to https://example/foo and https://example/foo/.
Therefore my question is: How can I fix this? Is this done somehow by the Wordpress system?
Enclosed you'll find my .htaccess file. I hope you can help me.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)
Could this be somehow caused by WordPress? I've mentioned this before, but there is also a rewrite code from WordPress.
# 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>
Share
Improve this question
edited Jan 6, 2019 at 18:39
MrWhite
3,8911 gold badge20 silver badges23 bronze badges
asked Jan 6, 2019 at 11:51
NiklasNiklas
531 silver badge7 bronze badges
1
|
1 Answer
Reset to default 0If you are doing this in .htaccess then I wouldn't try to do this in a single redirect. The longest "chain" should be two redirects (1, 2 or even 3 redirects makes no difference for SEO):
- Canonicalise the HTTP to HTTPS and www to non-www in the first redirect
- Append the trailing slash in the second redirect.
(If, however, you are implementing HSTS then you would need to implement the HTTP to HTTPS redirect (on the same hostname) first. Then canonicalise the subdomain. This potentially makes a maximum of 3 redirects.)
This appears to be what you are seeing in your first example.
It's possible to append the trailing slash in .htaccess, however, you've not shown this code so I'm assuming WordPress is configured to do this?
Currently, it redirects from
http://www.example/fooviahttp://example/footohttps://example/fooandhttps://example/foo/.
However, this doesn't correlate with the directives you posted, assuming these are at the top of your .htaccess file:
RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
These directives only redirect to https://, so it's not clear where your second stage redirect to http://example/foo is coming from? Unless maybe you are seeing a cached response?
Presumably, you are already linking to URLs with a trailing slash throughout your application, and you previously implemented a canonical www to non-www redirect, so any requests for http://www.example/foo should be a relatively rare occurrence. (?)
After implementing ssl on wordpress, I wanted to force a redirection to a site with the following characteristics:
non www, ssl, with trailing slash
Unfortunately it only works in some cases.
For instance, instead of redirecting from a site with these characteristics (http, non www, without trailing slash to https, non www with trailing slash), it redirects like this:
overto/.
I also have an issue with redirecting a www, http site without trailing slash to an https, non www, with trailing slash site.
Currently, it redirects from via to and /.
Therefore my question is: How can I fix this? Is this done somehow by the Wordpress system?
Enclosed you'll find my .htaccess file. I hope you can help me.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)
Could this be somehow caused by WordPress? I've mentioned this before, but there is also a rewrite code from WordPress.
# 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>
After implementing ssl on wordpress, I wanted to force a redirection to a site with the following characteristics:
non www, ssl, with trailing slash
Unfortunately it only works in some cases.
For instance, instead of redirecting from a site with these characteristics (http, non www, without trailing slash to https, non www with trailing slash), it redirects like this:
http://example/foooverhttps://example/footohttps://example/foo/.
I also have an issue with redirecting a www, http site without trailing slash to an https, non www, with trailing slash site.
Currently, it redirects from http://www.example/foo via http://example/foo to https://example/foo and https://example/foo/.
Therefore my question is: How can I fix this? Is this done somehow by the Wordpress system?
Enclosed you'll find my .htaccess file. I hope you can help me.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)
Could this be somehow caused by WordPress? I've mentioned this before, but there is also a rewrite code from WordPress.
# 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>
Share
Improve this question
edited Jan 6, 2019 at 18:39
MrWhite
3,8911 gold badge20 silver badges23 bronze badges
asked Jan 6, 2019 at 11:51
NiklasNiklas
531 silver badge7 bronze badges
1
-
The
.htaccessfile you've posted (in two parts) is not complete and the order of directives is important. This order is not clear from what you've posted. – MrWhite Commented Jan 6, 2019 at 19:05
1 Answer
Reset to default 0If you are doing this in .htaccess then I wouldn't try to do this in a single redirect. The longest "chain" should be two redirects (1, 2 or even 3 redirects makes no difference for SEO):
- Canonicalise the HTTP to HTTPS and www to non-www in the first redirect
- Append the trailing slash in the second redirect.
(If, however, you are implementing HSTS then you would need to implement the HTTP to HTTPS redirect (on the same hostname) first. Then canonicalise the subdomain. This potentially makes a maximum of 3 redirects.)
This appears to be what you are seeing in your first example.
It's possible to append the trailing slash in .htaccess, however, you've not shown this code so I'm assuming WordPress is configured to do this?
Currently, it redirects from
http://www.example/fooviahttp://example/footohttps://example/fooandhttps://example/foo/.
However, this doesn't correlate with the directives you posted, assuming these are at the top of your .htaccess file:
RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
These directives only redirect to https://, so it's not clear where your second stage redirect to http://example/foo is coming from? Unless maybe you are seeing a cached response?
Presumably, you are already linking to URLs with a trailing slash throughout your application, and you previously implemented a canonical www to non-www redirect, so any requests for http://www.example/foo should be a relatively rare occurrence. (?)
本文标签: htaccessHow can I fix the redirect chain after implementing ssl on wordpress
版权声明:本文标题:htaccess - How can I fix the redirect chain after implementing ssl on wordpress? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749019520a2304168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


.htaccessfile you've posted (in two parts) is not complete and the order of directives is important. This order is not clear from what you've posted. – MrWhite Commented Jan 6, 2019 at 19:05