0

I am using this GitHub page: https://github.com/Athlon1600/php-proxy-app and as it's supposed to, when I go to development.stech.software it loads up index.php.

When I choose a link, it makes it a query string like this development.stech.software/index.php?q=y6ml06abkWPdp6pnn6PVl6TLlMSkpmdvzdzUj6WZbqbWoQ (where the random characters is the query).

How do I adjust the index.php file, so that when I go to a URL, it loads it on /index.php/query/y6ml06abkWPdp6pnn6PVl6TLlMSkpmdvzdzUj6WZbqbWoQ or something similar.

I tried this, but it wouldn't work (it reported 500), I found it from URL rewriting with PHP

$path = ltrim($_SERVER['REQUEST_URI'], '/');    // Trim leading slash(es)
$elements = explode('/', $path);                // Split path on slashes
if(empty($elements[0])) {                       // No path elements means home
    ShowHomepage();
} else switch(array_shift($elements))             // Pop off first item and switch
{
    case 'index':
        ShowPicture($elements); // passes rest of parameters to internal function
        break;
    case 'more':
        ...
    default:
        header('HTTP/1.1 404 Not Found');
        Show404Error();
} 

I also added this to .htaccess FallbackResource htdocs/index.php

  • Can you share what you have tried so far? – Amit Verma May 24 '18 at 16:08
  • i've tried a lot of different things with .htaccess to do what I want, but it didn't work. that's why i'm trying it with php now. i've edited the question to show what i used. @starkeen – Shrey Gupta May 24 '18 at 16:16

1 Answers1

0

To redirect /index.php?q=foobar to /index.php/query/foobar you can use the following Rule in your htaccess file:

 FallbackResource htdocs/index.php

RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=(.+)$
RewriteRule ^index.php$ /index.php/query/%1? [L,R]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • How can I remove the .php, so that I can remove password protection for the query sub directory. Right now the link is [https://development.stech.software/index.php/query/index.php?q=QUERY], and my goal is to password protect access to index.php, but allow access to query. @starkeen – Shrey Gupta May 24 '18 at 18:18
  • Please don't use the comment sections to ask additional questions. Instead you should vote up good answers and hit the accept button if the *original question* has been answered. – Maarten Bodewes Nov 20 '20 at 21:49