How do I force a www subdomain on both HTTPS and HTTP?
How do I force a www subdomain on both HTTPS and HTTP? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How do I force a www subdomain on both HTTPS and HTTP? error on your web browser. Problem :
Solution :
We hope that this article has helped you resolve the apache, htaccess, redirects error in your web browsers. Enjoy browsing the internet uninterrupted!
For whatever reason I can’t seem to get this right. I’ve looked at many examples on here and on the Apache website. I’m trying to force www.example.com instead of example.com on both HTTP and HTTPS, but I am not trying to force use of HTTPS instead of HTTP.
The following code seems to work for all HTTPS connections, but will not cause a redirect for HTTP connections.
RewriteEngine On
RewriteCond %HTTPS on
RewriteCond %HTTP_HOST !^www.example.com$ [NC]
RewriteRule ^ https://www.example.com%REQUEST_URI [R=301]
RewriteEngine On
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST !^www.example.com$ [NC]
RewriteRule ^ http://www.example.com%REQUEST_URI [R=301]
Your solution seems right. But let me provide some checkpoints you can perform.
- Are HTTP and HTTPS set to point to the same physical directory?
- Have you tried asking on server fault?
- Can you try using modifiers to check like
Code:
RewriteEngine On
RewriteCond %HTTPS = on
RewriteCond %HTTP_HOST !^www.example.com$ [NC]
RewriteRule ^ https://www.example.com%REQUEST_URI [R=301,L]
RewriteCond %HTTPS != on
RewriteCond %HTTP_HOST !^www.example.com$ [NC]
RewriteRule ^ http://www.example.com%REQUEST_URI [R=301,L]
I've had the same problem, and the below solved it for me.
RewriteEngine On
RewriteCond %HTTP_HOST !^$
RewriteCond %HTTP_HOST ^example.com [NC]
RewriteCond %HTTPSs ^on(s)|
RewriteRule ^ http%1://www.%HTTP_HOST%REQUEST_URI [R=301,L]
Comments
Post a Comment