-2

I have a URL that looks like:

url.com/pages/login.php
url.com/pages/NewClient/index.php
url.com/pages/NewClient/page1.php
url.com/pages/NewClient/page2.php etc.

How would I go about converting that URL to:

url.com/login/
url.com/panel/
url.com/page1/
url.com/page2

How do I go about making friendly URLs in PHP?

  • 4
    Possible duplicate of [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – iainn Dec 17 '17 at 16:20

1 Answers1

0

For handling it in PHP, you can add the below line in the .htaccess file

FallbackResource route.php

This way all the URLs will get landed to route.php first.

This file will have all the logic for routing and mapping.

You can have the logic to look for the $_SERVER['REQUEST_URI'] and render content accordingly using basic condition statements.

For more information on FallbackResource directive, refer doc

Or for something as plain as your requirement, you can simply handle this directly in the .htaccess file by adding the below rules.

RewriteEngine On 
RewriteRule ^login$  pages/login.php   [NC,L]
RewriteRule ^panel$  pages/NewClient/index.php  [NC,L]
RewriteRule ^page1$  pages/NewClient/page1.php  [NC,L]
RewriteRule ^page2$  pages/NewClient/page2.php  [NC,L]
RamC
  • 1,287
  • 1
  • 11
  • 15