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?

  • Your script is located at `host/exercise` and you want to get `/math/lesson1` when `host/exercise/math/lesson1` is requested? – Y4roc Aug 09 '17 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` – Emily Virginita Aug 09 '17 at 17:10

1 Answers1

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'];
Y4roc
  • 1,066
  • 8
  • 12
  • 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` – Emily Virginita Aug 10 '17 at 15:10
  • I still get the folder name, e.g. for index page `/exercise/` and for `localhost/exercise/brrrr` page got `/exercise/brrrr` – Emily Virginita Aug 10 '17 at 20:17