3

I have url to index.php like this http://localhost/exercise/

When I call

return var_dump(
     trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')
);

I have exercise project folder in xampp's htdocs.

On url http://localhost/exercise/sd/ds I get exercise/sd/ds

How to get rid of that folder name in request_uri? Or any other (if there would be) folders if this php script was nested in some many folders.

How to get Request_URI started from this point where script is?

2
  • Your script is located at host/exercise and you want to get /math/lesson1 when host/exercise/math/lesson1 is requested?
    – Y4roc
    Commented Aug 9, 2017 at 12:56
  • I want just to have URI returned by REQUEST_URI to be page when I am on host/exercise/page, not exercise/page Commented Aug 9, 2017 at 17:10

1 Answer 1

0

After your comment, you can use a .htacces-file to resolved your problem. The .htaccess have to locate in the same folder as your script.

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /exercise/index.php?url=%1 [QSA]
</IfModule>

index.php:

$url = $_GET['url'];
2
  • This is bad solution for this and doesn't solve this particular problem. e.g. on http://localhost/exercise/sd/ds where script is in http://localhost/exercise/ and it is index.php URI string for http://localhost/exercise/sd/ds should be sd/ds, but with your solution it will be only ds Commented Aug 10, 2017 at 15:10
  • I still get the folder name, e.g. for index page /exercise/ and for localhost/exercise/brrrr page got /exercise/brrrr Commented Aug 10, 2017 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.