bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

URL Subfolder is visable #1176

Closed noXon68 closed 4 years ago

noXon68 commented 4 years ago

Hello, we changed PHP from 5.6 to 7.3 and F3 from 3.6 to 3.7, no more.

Data structure: /www/domain/ <- document root /www/domain/subfolder1 /www/domain/subfolder2 /www/domain/subfolder3 /www/domain/subfolderMain

Everything on /www/domain/, not subfolder1-3, should go to subfolderMain folder. However, the subfolderMain folder should not be visible in the URL.

/www/domain/.htaccess RewriteRule ^subfolder1/(.)$ - [L, QSA] RewriteRule ^subfolder2/(.)$ - [L, QSA] RewriteRule ^subfolder3/(.)$ - [L, QSA] RewriteRule ^(. )$ /SubfolderMain/$ 1 [QSA, L]

If we now call the URL "domain.com/test" the following happens: F3 3.6 & PHP 5.6 = the URL stays as it is (domain.com/test) F3 3.7 & PHP 7.3 = changes the URL to "domain.com/subfolderMain/test", only happens after starting F3. Before F3 starts running, the URL is unchanged (domain.com/test).

What can we do or change?

Thank you very much.

noXon68 commented 4 years ago

Hello, we changed PHP from 5.6 to 7.3 and F3 from 3.6 to 3.7, no more.

Data structure: /www/domain/ <- document root /www/domain/subfolder1 /www/domain/subfolder2 /www/domain/subfolder3 /www/domain/subfolderMain

Everything on /www/domain/, not subfolder1-3, should go to subfolderMain folder. However, the subfolderMain folder should not be visible in the URL.

/www/domain/.htaccess RewriteRule ^subfolder1/(.)$ - [L, QSA] RewriteRule ^subfolder2/(.)$ - [L, QSA] RewriteRule ^subfolder3/(.)$ - [L, QSA] RewriteRule ^(. )$ /SubfolderMain/$ 1 [QSA, L]

If we now call the URL "domain.com/test" the following happens: F3 3.6 & PHP 5.6 = the URL stays as it is (domain.com/test) F3 3.7 & PHP 7.3 = changes the URL to "domain.com/subfolderMain/test", only happens after starting F3. Before F3 starts running, the URL is unchanged (domain.com/test).

What can we do or change?

Thank you very much.

F3 3.6 & PHP 5.6 = no problems

F3 3.7 & PHP 7.3: domain.com/test <- no problem domain.com/test?t=007 <- no problem domain.com/test/ <- problem domain.com/test/?t=007 <- problem

quick&dirty, repalce /?t=007 to ?t=007 and the last / from domain.com/test/, bevor f3 starting run.

ikkez commented 4 years ago

It's currently not possible, and never was before, to add/allow a tailing / to your routes. I'll always reroute you to route without the / at the end. Depending on the 3.6.x version you was using, it could be that the reroute function had a bug, that allows invalid reroute paths.. since that was patched it's now guaranteed to use absolute locations, which probably leads to your described issue in your setup. If you don't want the base path added to your reroute path, clear the base path with $f3->BASE = ''; .. or try to set it to /. That should solve the problem.

noXon68 commented 4 years ago

Thx, $f3->BASE = ''; run but change or make redirect from "domain.com/what/" to "domain.com/what". We need the last / for A/B tests and analytics. My way, bevor F3 is starting:

    $_SERVER['REQUEST_URI'] = str_replace('/?','?',$_SERVER['REQUEST_URI']);
    strlen($_SERVER['REQUEST_URI']) > 2 && $_SERVER['REQUEST_URI'][strlen($_SERVER['REQUEST_URI'])-1] === '/'
        ? $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, -1)
        : null;

For me if F3 the best Framework but sometimes ... :)

ikkez commented 4 years ago

Well you can hack this behaviour by setting this before calling $f3->run(); $f3->PATH = rtrim($f3->PATH,'/');

But be aware, there be dragons.

noXon68 commented 4 years ago

Thx ikkez, $f3->PATH = rtrim($f3->PATH,'/'); do it.