Trying to use PATH_INFO for url shortening

I tried to use the $SERVER[“PATH_INFO”] variable but when you try to do it in the / folder, it gives you a 404 error.
http://ebtc.ml/Jd1FAH
http://ebtc.ml/index.php/Jd1FAH
My testing with my home server just works fine, this is a redirect bug.

it is $_SERVER[“PATH_INFO”];

Warning: preg_replace(): Unknown modifier 'g' in /home/vol5_6/epizy.com/epiz_22870987/ebtc.ml/htdocs/continue/index.php on line 2

Warning: strlen() expects exactly 1 parameter, 2 given in /home/vol5_6/epizy.com/epiz_22870987/ebtc.ml/htdocs/continue/index.php on line 2
array(2) { ["g-recaptcha-response"]=> string(505) "03AOLTBLSgDYZbrw5WlLi09yTywnPKtvRsxopNDC3PVCmpMxq2JnjqcNkjOmaCbu84c5mVlwNQZ69C-Pkhi4BioDokJS4aX-wohv-jBjnZk7O6sfj3AELFYcyC6kXDCxLVglxWvr-PfiVa6rnprWYEjh-HDKhQpsP7lZFSBjqllAcs4MjsqRpmyjfsV_LlBHXdLnHdcUWfMishuVeIoPQ_2odkeDaA5QN6mzmsLwPaVeAw6VlPqpEwVwWjGE3rrmrhEMbz99C9gI_DUKFHdIctWxCLC-3ahU0ek9Q3Y9ohhJoHCZQXAnW0jem_gY9gK22YiJYRgREFqoOEclqyiPf36sL1jGyBYePQPzQb5irwubYn3ifa7lBJXOJ2bFZMBsG0vZ38Pa5d4uTpSBPuLwg2_nGQO1-Zk9q9jOBIh39sY8vtYfKH4Iup9j9flxl9PNaD2_sLhmtxjdTe_KOtRUBdITdyfjUstngAqLPoZh232jkte1qMLQ1rz2w" ["urlKey"]=> string(6) "aaaaaa" }

i got this bug while trying example url.

when trying other side. it gives me http://ebtc.ml/?fLtYHJ

I was talking about this type of links:
http://ebtc.ml/Jd1FAH
Also yes it is $_SERVER
My code for checking in /index.php is:
$input = $_SERVER[‘PATH_INFO’];
if (strlen(preg_replace(“/[^a-zA-Z0-9]/”,“”,$input)) == 6)
But it just gives me 404 when I try to visit http://ebtc.ml/Jd1FAH

Simply clear your cache :slight_smile:

1 Like

If that works im paying you in NANO

Sorry, didn’t work. I found a workoaround thom Just simply create a 404.php, use the HTTP_REFERRER (or something like that) to do it. Will cost an extra hour but better than changimg hosting services.

The URL http://ebtc.ml/index.php/Jd1FAH works, indicating that PATH_INFO just works as intended.

The URL http://ebtc.ml/Jd1FAH does not work. However, I checked your .htaccess file, and don’t see any rewrite rules to route that URL to your PHP code. Instead, it’s just handled by your ErrorDocument 404 clause, so the page is redirected to your home page.

I suspect that if you add the .htaccess rules to route the first URL to your index.php script, it will work.

And if this is what the ErrorDocument is supposed to do, you may want to switch that from a full URL to a file path instead (e.g. /index.php). If you specify a URL, that means the server will send a redirect, so all reference related to the original request URL is gone.

Although that still wouldn’t give you the PATH_INFO parameter. You’ll need rewrite rules to do that.

1 Like

Thank you for your respone, but how do I exactly write a rule for that?

If I had to quickly whip something together, I’d say the rules would look something like:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

That said, you’ll probably find plenty of examples which are probably more well tested if you just search the web.

3 Likes

Thank you! That saved the entire project. Now it is almost finished.

1 Like

I just tried to use your site, I think something might be broken on your submit.php page.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.