Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a PHP web page without the .php extension in the URL?

Tags:

Sorry for noob question, can't understand from what I should search.

I'm making a site with that page product.php?id=777
I'd like it to be product/777

Thank you!

like image 324
Tuco Avatar asked Apr 08 '11 00:04

Tuco


People also ask

How do I run a PHP script from a website?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

Can I run PHP code without a web server?

You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks.


2 Answers

Create .htaccess file in your web root and enter following there:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^product/([0-9]+)$ product.php?id=$1
like image 94
arma Avatar answered Sep 28 '22 08:09

arma


Instead of using mod_rewrite you can also use following in your .htaccess:

 DefaultType application/x-httpd-php 

And just name your script product on the server (without .php file extension).

So you can invoke it directly and would receive any appended string as $_SERVER["PATH_INFO"]

like image 34
mario Avatar answered Sep 28 '22 10:09

mario