-1

CakePHP Version: 3.6

I created a project with 3 route prefixes: admin, vendor and customer.

On my local machine it is working fine, all the prefixes are working fine. I moved my project to a remote Linux server and it was working fine at first. Once I added an SSL certificate and I access my website like this:

https://subdomain.myproject.com/vendor

It does not work. The browser keeps loading, and after some time it shows This site can’t be reached took too long to respond.

If I add a trailing slash it is working fine:

https://subdomain.myproject.com/vendor/

Other than the vendor prefix, the other prefixes are working fine as expected. Is it because CakePHP has a vendor folder or is it because of a server redirection?

Please guide me, how do I redirect http to https? I have added something to .htaccess, but it is also showing a 'too many redirects' issue.

BadHorsie
  • 14,135
  • 30
  • 117
  • 191

1 Answers1

0

If you have mod_dir enabled in Apache, it should by default automatically redirect your requests to the same URL with a trailing slash. From the Apache documentation:

A "trailing slash" redirect is issued when the server receives a request for a URL http://servername/foo/dirname where dirname is a directory. Directories require a trailing slash, so mod_dir issues a redirect to http://servername/foo/dirname/

It's likely you do have this enabled, but check.

is it because cakephp has vendor folder

The vendor directory should not be publicly accessible in CakePHP, and I wouldn't expect there to be any issue with having a vendor routing prefix.

how to redirect http to https

Your .htaccess should look something like this, to force an HTTPS redirect and ensure CakePHP functions correctly:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    # SSL redirect
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Required for CakePHP
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]

</IfModule>
BadHorsie
  • 14,135
  • 30
  • 117
  • 191