1

I want to hide filenames (URL masking).

These are the URL's I have with my project:

http://example.com/add_candidate.php?id=12
http://example.com/admin/access_author.php
http://example.com/associate/support/edit_profile.php?a_id=10

My URLs should URLs look like:

http://example.com/
http://example.com/admin/
http://example.com/associate/support/

How is this possible?

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Kavya Shree
  • 1,014
  • 2
  • 17
  • 52

2 Answers2

0

It's not actually a php issue. :)

If you are using Apache HTTP server, you may want to take a look at .htaccess and mod_rewrite. They are Apache features that map a server URL into a PHP script.
For example:

http://example.com/associate/support/

to

http://example.com/associate/support/edit_profile.php?a_id=10

Here's a nice tutorial on how to accomplish that:
https://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Omar Alves
  • 763
  • 5
  • 13
0

You can plug in any routing Library. Personally, I find Bramus Router (https://github.com/bramus/router) quite easy to integrate into existing projects.

First, you create a .htaccess file at the root of your project like this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

This makes Apache pass all requests to the index.php file where we then define our routes like this:

// Static route: /hello
$router->get('/hello', function () {
    echo '<h1>bramus/router</h1><p>Visit <code>/hello/<em>name</em></code> to get your Hello World mojo on!</p>';
});
B. Go
  • 1,436
  • 4
  • 15
  • 22