1

I have two webpage link together like when a button is press it leads to the second webpage. my problem is that I'm trying to get a clean url with the .php removed. now my url looks like this

http://localhost/ecommer%20flower%20shop/flowers/list.php

and the second webpage

http://localhost/ecommer%20flower%20shop/flowers/about.php.

i want my url to be like

http://localhost/ecommer flower shop/

http://localhost/ecommer flower shop/about

the code i have written for this in index.php

<?php

if ($_SERVER['REQUEST_URI'] == '/') {
    # code...
    return include_once './flowers/list.php';
}

if ($_SERVER['REQUEST_URI'] == '/about') {
    # code...
    return include_once './flowers/about.php';
}

but this is not working and gives blank page, i don't know my mistake or what to do to fix code

bhs
  • 11
  • 2
  • First you'll need some rewrite rules in your webserver to direct non `.php` requests to PHP. There are lots of examples of this sort of thing online already if you search - you don't need to struggle alone. But also we probably don't need to repeat them again here. – ADyson May 12 '22 at 11:29
  • You need to use .htaccess for it and to be specific it's called pretty URL. If you google that you should get much info on how to. https://stackoverflow.com/questions/25080835/pretty-urls-with-htaccess – Kip May 12 '22 at 11:29
  • You should do a "url re write" with your hosting software, nginx or apache. Nginx https://www.thegeekstuff.com/2017/08/nginx-rewrite-examples/ Apache https://fedingo.com/how-to-rewrite-url-to-another-url-in-apache/ – MisterG13 May 12 '22 at 12:18

2 Answers2

1

Default setting of servers software search in directions index files (index.html, index.php). If you rebuild your catalog it can work like you want

/flowers/index.php (/flowers)

/flowers/about/index.php (/flowers/about)

/flowers/something/index.php (flowers/something)

7-zete-7
  • 712
  • 4
  • 12
0

You can use Apache mod_rewrite for this.

write this in your Apache httpd.conf file

RewriteEngine On
RewriteRule (.*)/about$ ($1)/about.php
RewriteRule (.*)/list$ ($1)/list.php

Now you can request http://localhost/flowers/list and Apache will send that request to the file http://localhost/flowers/list.php

Accountant م
  • 6,975
  • 3
  • 41
  • 61