-1

I am a beginner of php. I am trying to create a website using php. I have pages called index.php, about.php, contact.php, etc.. I have a menus called home, About, Contact, etc.. I want the menus link should be like this http://localhost/mysite/about, http://localhost/mysite/contactus, etc.. I want to call the corresponding page to that particular link. What I tried is,

<a href="index.php">Home</a>
<a href="about.php">About</a>
<a href="contact.php">Contact</a>

When I click the home menu its going to the page with URL like http://localhost/mysite/index.php and about menu going to http://localhost/mysite/about.php but what I need is When I click About menu, its going to that page with URL like http://localhost/mysite/about. Without php extension, its going to that page.

Any help would be appreciated. Thanks

Preethi
  • 109
  • 9

3 Answers3

0

You just need to add a .htaccess file in your root directory and add the following in this:

RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
Ankit Singh
  • 1,477
  • 1
  • 13
  • 22
0

Add these two lines to your htaccess file.

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

I hope it helps.

Stackgeek
  • 227
  • 1
  • 12
0

.htaccess files affect the directory in which they are placed and all sub-directories

Removing Extensions

**Add following code inside the .htaccess file:**
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Shanu k k
  • 1,235
  • 2
  • 18
  • 43