Home » Php » apache – .htaccess routing PHP

apache – .htaccess routing PHP

Posted by: admin July 12, 2020 Leave a comment


I am trying to write some simple routing in htaccess for PHP

My file looks like this for now:

RewriteEngine On
RewriteBase /webservices/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ server.php [QSA,L]

But it does nothing.

The thing that I want with htaccess is that all the calls to server.php are caught like this:


to be written


Can someone help me with that?

How to&Answers:

It is actually working, because it redirects all queries to server.php. Therefore


can be handled by server.php, where you can easily catch parts of the URI using explode() on the $_SERVER["REQUEST_URI"] array. Forget the


URL structure, you won’t need it anymore, because using the .htaccess you’ve just written, you can dynamically handle every request to your server on server.php.

[QSA] in your .htaccess appends query string to the URI, which is not needed, because we want to get rid of it, right? Since you wont use that format, you can remove QSA flag.