Press enter to see results or esc to cancel.


Hide .php extensions, Custom url for PHP pages with parameters, htaccess


In this video I have shown how you can have custom URL for you PHP web site.
It is done by htaccess file, Please note that htaccess file should be created in ROOT folder of your project.

1. Project files


Web pages
2. index.php

<a href="index.php">INDEX</a> | <a href="ABOUT">ABOUT</a> | <a href="PRODUCT">PRODUCT</a> | <a href="CONTACT">CONTACT</a> |<a href="IMAGE">IMAGE</a> | <br> <br>

index page

After running the file on server
http://localhost/

3. about.php

<a href="index.php">INDEX</a> | <a href="ABOUT">ABOUT</a> | <a href="PRODUCT">PRODUCT</a> | <a href="CONTACT">CONTACT</a> |<a href="IMAGE">IMAGE</a> | <br> <br>

about page

After running the about.php file on server
http://localhost/ABOUT


4. product.php

<a href="index.php">INDEX</a> | <a href="ABOUT">ABOUT</a> | <a href="PRODUCT">PRODUCT</a> | <a href="CONTACT">CONTACT</a> |<a href="IMAGE">IMAGE</a> | <br> <br>

product page

After running the product.php file on server
http://localhost/PRODUCT

5. contact.php

<a href="index.php">INDEX</a> | <a href="ABOUT">ABOUT</a> | <a href="PRODUCT">PRODUCT</a> | <a href="CONTACT">CONTACT</a> |<a href="IMAGE">IMAGE</a> | <br> <br>

contactpage

After running the contact.php file on server
http://localhost/CONTACT


6. image.php
After running the image.php file on server
http://localhost/IMAGE


<a href="index.php">INDEX</a> | <a href="ABOUT">ABOUT</a> | <a href="PRODUCT">PRODUCT</a> | <a href="CONTACT">CONTACT</a> | <br> <br>
image page
<br>
<?php
if(isset($_GET['param1'])){
echo $_GET['param1'].'<br>';
}
if(isset($_GET['param2'])){
echo $_GET['param2'].'<br>';
}
if(isset($_GET['param3'])){
echo $_GET['param3'];
}
?>

/IMAGE with one, two and three parameters are shown.

7. .htaccess file


RewriteEngine on  
  
RewriteRule ^ABOUT  about.php [NC,L]
RewriteRule ^CONTACT  contact.php [NC,L]
RewriteRule ^PRODUCT  product.php [NC,L] 


RewriteRule ^IMAGE/([a-zA-Z0-9\-=&_@\.\,\)\(]*)/([a-zA-Z0-9\-=&_@\.\,\)\(]*)/([a-zA-Z0-9\-=&_@\.\,\)\(]*)$ /image_folder/image.php?param1=$1&param2=$2&param3=$3 [NC,L]
RewriteRule ^IMAGE/([a-zA-Z0-9\-=&_@\.\,\)\(]*)/([a-zA-Z0-9\-=&_@\.\,\)\(]*)$ /image_folder/image.php?param1=$1&param2=$2 [NC,L]
RewriteRule ^IMAGE/([a-zA-Z0-9\-=&_@\.\,\)\(]*)$ /image_folder/image.php?param1=$1 [NC,L]
RewriteRule ^IMAGE image_folder/image.php [NC,L]

8. Download the complete project here

customurl

Comments

Comments are disabled for this post