Link to home
Start Free TrialLog in
Avatar of jagku
jagkuFlag for United States of America

asked on

.htaccess redirect to https help (currently it is looping)

I have the following code:

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]

Open in new window


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?
Avatar of Dr. Klahn
Dr. Klahn

Turn on mod_rewrite logging and you'll be able to see what is going on.  The log will show every step in the rewrite and this should clear up the issue.  

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.
Avatar of jagku

ASKER

Thanks. Looks like I didn't have RewriteCond %{SERVER_PORT} 80  declared.
ASKER CERTIFIED SOLUTION
Avatar of jagku
jagku
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial