Mautic Community Forums

Installing Mautic in a subdirectory, getting constant redirect

Hello, I am trying to install Mautic in a subdirectory on https://mautic.perlur.cz/prevencecz/ and https://mautic.perlur.cz/perlurgroup/, however, when I try to open Mautic on those web addresses, I am gettitng redirected to “https://mautic.perlur.cz/s/login” (without the sub-directory), so I always get 404 Not Found HTTP error. Does anybody have similar experience?

Code:
[root@glczwe-sp230001 prevencecz]# curl -vvvv https://mautic.perlur.cz/prevencecz/ -L * About to connect() to mautic.perlur.cz port 443 (#0) * Trying 2400:cb00:2048:1::681c:1836... * Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 * Server certificate: * subject: CN=sni40127.cloudflaressl.com,OU=PositiveSSL Multi-Domain,OU=Domain Control Validated * start date: Feb 13 00:00:00 2016 GMT * expire date: Aug 21 23:59:59 2016 GMT * common name: sni40127.cloudflaressl.com * issuer: CN=COMODO ECC Domain Validation Secure Server CA 2,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB > GET /prevencecz/ HTTP/1.1 > User-Agent: curl/7.29.0 > Host: mautic.perlur.cz > Accept: */* > < HTTP/1.1 302 Found < Server: cloudflare-nginx < Date: Fri, 19 Feb 2016 09:22:11 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Set-Cookie: __cfduid=df4f763c24769a2c1f35381bd0f4a6b981455873731; expires=Sat, 18-Feb-17 09:22:11 GMT; path=/; domain=.perlur.cz; HttpOnly < X-Powered-By: PHP/5.5.32 < Set-Cookie: b23262d5a2331b55341398d7619a6f79=5oj73ut85u1tp5hjoar26tuvo4; path=/ < Cache-Control: no-cache < Location: /prevencecz/s/dashboard < CF-RAY: 2770e7e577b73de4-PRG < * Ignoring the response-body * Connection #0 to host mautic.perlur.cz left intact * Issue another request to this URL: 'https://mautic.perlur.cz/prevencecz/s/dashboard' * Found bundle for host mautic.perlur.cz: 0x2010da0 * Re-using existing connection! (#0) with host mautic.perlur.cz * Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0) > GET /prevencecz/s/dashboard HTTP/1.1 > User-Agent: curl/7.29.0 > Host: mautic.perlur.cz > Accept: */* > < HTTP/1.1 302 Found < Server: cloudflare-nginx < Date: Fri, 19 Feb 2016 09:22:12 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Set-Cookie: __cfduid=df4f763c24769a2c1f35381bd0f4a6b981455873731; expires=Sat, 18-Feb-17 09:22:11 GMT; path=/; domain=.perlur.cz; HttpOnly < X-Powered-By: PHP/5.5.32 < Set-Cookie: b23262d5a2331b55341398d7619a6f79=obmt6q39b6e8ec9c7jgsjfaa33; path=/ < Cache-Control: no-cache < Location: http://mautic.perlur.cz/prevencecz/s/login < CF-RAY: 2770e7e7b7bd3de4-PRG < * Ignoring the response-body * Connection #0 to host mautic.perlur.cz left intact * Issue another request to this URL: 'http://mautic.perlur.cz/prevencecz/s/login' * Found bundle for host mautic.perlur.cz: 0x2010da0 * About to connect() to mautic.perlur.cz port 80 (#1) * Trying 2400:cb00:2048:1::681c:1836... * Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 80 (#1) > GET /prevencecz/s/login HTTP/1.1 > User-Agent: curl/7.29.0 > Host: mautic.perlur.cz > Accept: */* > < HTTP/1.1 302 Found < Date: Fri, 19 Feb 2016 09:22:12 GMT < Content-Type: text/html; charset=iso-8859-1 < Transfer-Encoding: chunked < Connection: keep-alive < Set-Cookie: __cfduid=ddca5986cb1895e1aca9d12642ae93d541455873732; expires=Sat, 18-Feb-17 09:22:12 GMT; path=/; domain=.perlur.cz; HttpOnly < Location: https://mautic.perlur.cz/s/login < Server: cloudflare-nginx < CF-RAY: 2770e7e9e1053e32-PRG < * Ignoring the response-body * Connection #1 to host mautic.perlur.cz left intact * Issue another request to this URL: 'https://mautic.perlur.cz/s/login' * Found bundle for host mautic.perlur.cz: 0x2010da0 * Re-using existing connection! (#0) with host mautic.perlur.cz * Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0) > GET /s/login HTTP/1.1 > User-Agent: curl/7.29.0 > Host: mautic.perlur.cz > Accept: */* > < HTTP/1.1 404 Not Found < Server: cloudflare-nginx < Date: Fri, 19 Feb 2016 09:22:12 GMT < Content-Type: text/html; charset=iso-8859-1 < Transfer-Encoding: chunked < Connection: keep-alive < Set-Cookie: __cfduid=d91489783d60812565aeca4bfc424e4361455873732; expires=Sat, 18-Feb-17 09:22:12 GMT; path=/; domain=.perlur.cz; HttpOnly < CF-RAY: 2770e7ea07c33de4-PRG < 404 Not Found

Not Found

The requested URL /s/login was not found on this server.


Apache/2.4.6 (CentOS) PHP/5.5.32 mod_perl/2.0.9dev Perl/v5.16.3 Server at mautic.perlur.cz Port 80 * Connection #0 to host mautic.perlur.cz left intact [root@glczwe-sp230001 prevencecz]#

My .htaccess is pretty standard, I just added a check to force HTTPs via CloudFlare and RewriteBase, however I have been getting the same error even prior to making my modifications.
Code:
# Use the front controller as index file. It serves as a fallback solution when # every other rewrite/redirect fails (e.g. in an aliased environment without # mod_rewrite). Additionally, this reduces the matching process for the # start page (path "/") because otherwise Apache will apply the rewriting rules # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). DirectoryIndex index.php RewriteEngine On
RewriteBase "/prevencecz/"

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]


# Set Authorization header for OAuth1a for when php is running under fcgi
#RewriteCond %{HTTP:Authorization} .+
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::2$
RewriteRule ^(.*) - [E=BASE:%1]

# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
#   following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/index.php [L]

<IfModule !mod_rewrite.c>

# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^(?!/(index.php|index_dev.php|app|addons|plugins|media|upgrade))(/(.*))$ /index.php$2
# RedirectTemp cannot be used instead

We have fixed this problem by installing mautic in root directory. Please let me know if I can help any one.

We are having the same issue. Any one?

I’m having this same problem on two different LEMP servers. So I tried the identical process on my LAMP box and it works perfectly. Does anyone have a solution to install mautic in a subdirectory of a site on nginx?

Got it figured out:

https://www.mautic.org/community/index.php/4966-install-on-nginx-and-in-subfolder/p1#p13339

Hello, I am trying to install Mautic in a subdirectory on https://mautic.perlur.cz/prevencecz/ and https://mautic.perlur.cz/perlurgroup/, however, when I try to open Mautic on those web addresses, I am gettitng redirected to “https://mautic.perlur.cz/s/login” (without the sub-directory), so I always get 404 Not Found HTTP error. Does anybody have similar experience?

[root@glczwe-sp230001 prevencecz]# curl -vvvv https://mautic.perlur.cz/prevencecz/ -L
* About to connect() to mautic.perlur.cz port 443 (#0)
*   Trying 2400:cb00:2048:1::681c:1836...
* Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=sni40127.cloudflaressl.com,OU=PositiveSSL Multi-Domain,OU=Domain Control Validated
*       start date: Feb 13 00:00:00 2016 GMT
*       expire date: Aug 21 23:59:59 2016 GMT
*       common name: sni40127.cloudflaressl.com
*       issuer: CN=COMODO ECC Domain Validation Secure Server CA 2,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB
> GET /prevencecz/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mautic.perlur.cz
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: cloudflare-nginx
< Date: Fri, 19 Feb 2016 09:22:11 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=df4f763c24769a2c1f35381bd0f4a6b981455873731; expires=Sat, 18-Feb-17 09:22:11 GMT; path=/; domain=.perlur.cz; HttpOnly
< X-Powered-By: PHP/5.5.32
< Set-Cookie: b23262d5a2331b55341398d7619a6f79=5oj73ut85u1tp5hjoar26tuvo4; path=/
< Cache-Control: no-cache
< Location: /prevencecz/s/dashboard
< CF-RAY: 2770e7e577b73de4-PRG
<
* Ignoring the response-body
* Connection #0 to host mautic.perlur.cz left intact
* Issue another request to this URL: 'https://mautic.perlur.cz/prevencecz/s/dashboard'
* Found bundle for host mautic.perlur.cz: 0x2010da0
* Re-using existing connection! (#0) with host mautic.perlur.cz
* Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0)
> GET /prevencecz/s/dashboard HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mautic.perlur.cz
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: cloudflare-nginx
< Date: Fri, 19 Feb 2016 09:22:12 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=df4f763c24769a2c1f35381bd0f4a6b981455873731; expires=Sat, 18-Feb-17 09:22:11 GMT; path=/; domain=.perlur.cz; HttpOnly
< X-Powered-By: PHP/5.5.32
< Set-Cookie: b23262d5a2331b55341398d7619a6f79=obmt6q39b6e8ec9c7jgsjfaa33; path=/
< Cache-Control: no-cache
< Location: http://mautic.perlur.cz/prevencecz/s/login
< CF-RAY: 2770e7e7b7bd3de4-PRG
<
* Ignoring the response-body
* Connection #0 to host mautic.perlur.cz left intact
* Issue another request to this URL: 'http://mautic.perlur.cz/prevencecz/s/login'
* Found bundle for host mautic.perlur.cz: 0x2010da0
* About to connect() to mautic.perlur.cz port 80 (#1)
*   Trying 2400:cb00:2048:1::681c:1836...
* Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 80 (#1)
> GET /prevencecz/s/login HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mautic.perlur.cz
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Fri, 19 Feb 2016 09:22:12 GMT
< Content-Type: text/html; charset=iso-8859-1
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=ddca5986cb1895e1aca9d12642ae93d541455873732; expires=Sat, 18-Feb-17 09:22:12 GMT; path=/; domain=.perlur.cz; HttpOnly
< Location: https://mautic.perlur.cz/s/login
< Server: cloudflare-nginx
< CF-RAY: 2770e7e9e1053e32-PRG
<
* Ignoring the response-body
* Connection #1 to host mautic.perlur.cz left intact
* Issue another request to this URL: 'https://mautic.perlur.cz/s/login'
* Found bundle for host mautic.perlur.cz: 0x2010da0
* Re-using existing connection! (#0) with host mautic.perlur.cz
* Connected to mautic.perlur.cz (2400:cb00:2048:1::681c:1836) port 443 (#0)
> GET /s/login HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mautic.perlur.cz
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: cloudflare-nginx
< Date: Fri, 19 Feb 2016 09:22:12 GMT
< Content-Type: text/html; charset=iso-8859-1
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d91489783d60812565aeca4bfc424e4361455873732; expires=Sat, 18-Feb-17 09:22:12 GMT; path=/; domain=.perlur.cz; HttpOnly
< CF-RAY: 2770e7ea07c33de4-PRG
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /s/login was not found on this server.</p>
<hr>
<address>Apache/2.4.6 (CentOS) PHP/5.5.32 mod_perl/2.0.9dev Perl/v5.16.3 Server at mautic.perlur.cz Port 80</address>
</body></html>
* Connection #0 to host mautic.perlur.cz left intact
[root@glczwe-sp230001 prevencecz]#

My .htaccess is pretty standard, I just added a check to force HTTPs via CloudFlare and RewriteBase, however I have been getting the same error even prior to making my modifications.

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase "/prevencecz/"

    RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]


    # Set Authorization header for OAuth1a for when php is running under fcgi
    #RewriteCond %{HTTP:Authorization} .+
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Determine the RewriteBase automatically and set it as environment variable.
    # If you are using Apache aliases to do mass virtual hosting or installed the
    # project in a subdirectory, the base path will be prepended to allow proper
    # resolution of the app.php file and to redirect to the correct URI. It will
    # work in environments without path prefix as well, providing a safe, one-size
    # fits all solution. But as you do not need it in this case, you can comment
    # the following 2 lines to eliminate the overhead.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # Redirect to URI without front controller to prevent duplicate content
    # (with and without `/app.php`). Only do this redirect on the initial
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
    # endless redirect loop (request -> rewrite to front controller ->
    # redirect -> request -> ...).
    # So in case you get a "too many redirects" error or you always get redirected
    # to the start page because your Apache does not expose the REDIRECT_STATUS
    # environment variable, you have 2 choices:
    # - disable this feature by commenting the following 2 lines or
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
    #   following RewriteCond (best solution)
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^(?!/(index.php|index_dev.php|app|addons|plugins|media|upgrade))(/(.*))$ /index.php$2
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>