'I'm trying to write a clean url for my website using the $_SERVER['REQUEST_URI'] in php
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
Solution 1:[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
)
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | 7-zete-7 |
Solution 2 | Accountant Ù… |