Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http to https getting too many redirects #2623

Closed
sathish1981 opened this issue Mar 18, 2020 · 10 comments
Closed

http to https getting too many redirects #2623

sathish1981 opened this issue Mar 18, 2020 · 10 comments
Labels
bug

Comments

@sathish1981
Copy link

@sathish1981 sathish1981 commented Mar 18, 2020

Hello @ozh
I have configured Yourls with PHP7 and apache 2.4. I was able to get the yourls running fine and tested all features in HTTP.
When we acquired the SSL cert and applied HTTPS to apache and yourls like below,
define( 'YOURLS_SITE', 'http://short.me' );
define( 'YOURLS_ADMIN_SSL', true );

Once after we enable the SSL true statement in config.php, I am getting too many redirects while accessing the admin page. If I comment the statement in config.php, the admin page works fine.

I looked on all other tickets which discussed this matter but no one had this problem.

Am I missing something?

@sathish1981 sathish1981 added the bug label Mar 18, 2020
@dgw

This comment has been minimized.

Copy link
Member

@dgw dgw commented Mar 18, 2020

Could be helpful to see a network log from your browser's dev tools to see what is looping.

Also, if you haven't tried it, see what happens if you set https in YOURLS_SITE.

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 18, 2020

irrespective of YOURLS_SITE protocol its looping the same address if the SSL is set true.

In network logs also i am seeing the same looping issue like below
https://short.me/admin to https://short.me/admin

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 18, 2020

Also one more update,
I even tried to force apache to load the domain in HTTPS by redirecting all traffic from HTTP (without setting SSL to true in config.php).
The /admin page worked fine, but i was not able to access the stats and short urls are not getting redirected. in both instance I got 404

I am trying in all possible ways but no luck :(

@ozh

This comment has been minimized.

Copy link
Member

@ozh ozh commented Mar 18, 2020

I confirm I cannot reproduce this.

Expected behavior:

  • if you edit YOURLS_SITE to specify "https", it just works (you're logged out but that's all and once you log back in nothing works differently)
  • if you also add YOURLS_ADMIN_SSL to your config, it enforces the redirection from http to https, but again, nothing works differently apart from a redirection if you attempt to load http

Given how it works on my side and the absence of issues on the matter, I think it mostly works as expected everywhere.

Back to your specific case : does it happen only with YOURLS? If you have a page outside yourls, is there anything weird happening? (eg https://notyourls/somepage isn't reachable?)

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 18, 2020

I confirm I cannot reproduce this.

Expected behavior:

  • if you edit YOURLS_SITE to specify "https", it just works (you're logged out but that's all and once you log back in nothing works differently)
  • if you also add YOURLS_ADMIN_SSL to your config, it enforces the redirection from http to https, but again, nothing works differently apart from a redirection if you attempt to load http

Given how it works on my side and the absence of issues on the matter, I think it mostly works as expected everywhere.

Back to your specific case : does it happen only with YOURLS? If you have a page outside yourls, is there anything weird happening? (eg https://notyourls/somepage isn't reachable?)

Yes @ozh , I was able to access the other pages without issues. I having issues only when accessing /admin which is causing redirect loops. But when I comment the SSL true line from config.php. everything works perfectly. But I need to configure in HTTPS

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 18, 2020

Below is my Apache yourls configuration, I have allowed both http and https
Note : All end stags are stripped out by git by default.

<VirtualHost :80>
ServerName short.me
ServerAlias www.short.me
DocumentRoot /var/www/html
<Directory /var/www/html>
# BEGIN YOURLS

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.
$ /yourls-loader.php [L]

# END YOURLS

ErrorLog "| /usr/sbin/rotatelogs -l /var/log/httpd/short.me-error_log-%Y%m%d 86400"
CustomLog "| /usr/sbin/rotatelogs -l /var/log/httpd/short.me-access_log-%Y%m%d 86400" combined

<VirtualHost :443>
ServerName short.me
ServerAlias www.short.me
DocumentRoot /var/www/html
<Directory /var/www/html>
# BEGIN YOURLS

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.
$ /yourls-loader.php [L]

# END YOURLS

ErrorLog "| /usr/sbin/rotatelogs -l /var/log/httpd/short.me-HTTPS-error_log-%Y%m%d 86400"
CustomLog "| /usr/sbin/rotatelogs -l /var/log/httpd/short.me-HTTPS-access_log-%Y%m%d 86400" combined

@ozh

This comment has been minimized.

Copy link
Member

@ozh ozh commented Mar 18, 2020

Wait... if you have

define( 'YOURLS_SITE', 'http://short.me' );
define( 'YOURLS_ADMIN_SSL', true );

as stated, it cannot work indeed. You need to define YOURLS_SITE with the https URL

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 19, 2020

@ozh
I tried to point HTTPS as well in YOURLS_SITE both didn't work. Both HTTP and HTTPS is working fine when the SSL line is disabled.

@sathish1981

This comment has been minimized.

Copy link
Author

@sathish1981 sathish1981 commented Mar 19, 2020

@ozh : I used the latest build which got downloaded on 16/03
Plugins : Sleeky theme, Auth mang plus, Random short urls

Update:
OKay, now I disabled the SSL option in config file and forced Apache to redirect HTTP traffic to HTTPS.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note: You need to keep the 80 and 443 both port to accept the traffic in the above scenario. If you restrict the http incoming traffic then short url redirect and stats feature wont work.

After the above settings, all feature worked as expected. Not faced any issues yet 👍

Will let u know, if something happens :)
[Still the SSL option is a mystery to me]

@ozh

This comment has been minimized.

Copy link
Member

@ozh ozh commented Mar 28, 2020

Marking this as closed but feel free to report any additional info if the problem persists.

@ozh ozh closed this Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.