jagku
asked on
.htaccess redirect to https help (currently it is looping)
I have the following code:
First redirect redirects www.example.com/xyz to www.example.com/xyz.php.
This works fine.
Second one has a problem. If I type in example.com, it creates an infinite loop to:
https://example.com/example.com/example.com
If I type in www.example.com, it also creates an infinite loop similar to the above.
I want to redirect everything from:
http://example.com/... https://example.com/... to https://www.example.com/...
What am I missing here?
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteRule ^xyz xyz.php [PT]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
First redirect redirects www.example.com/xyz to www.example.com/xyz.php.
This works fine.
Second one has a problem. If I type in example.com, it creates an infinite loop to:
https://example.com/example.com/example.com
If I type in www.example.com, it also creates an infinite loop similar to the above.
I want to redirect everything from:
http://example.com/... https://example.com/... to https://www.example.com/...
What am I missing here?
ASKER
Thanks. Looks like I didn't have RewriteCond %{SERVER_PORT} 80 declared.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on whether the server is V2.2 or V2.4, the procedure is different.
https://wiki.apache.org/httpd/RewriteLog
Caution: Do this on an isolated, testbed server. The logs grow enormous very rapidly otherwise and are so unreadable as to be useless.