2017-07-21 55 views
-1

我是一个PHP的初学者。我正在尝试使用php创建一个网站。我有一个名为index.php,about.php,contact.php等的页面。我有一个名为home,About,Contact等的菜单。我想要菜单链接应该是这样的http://localhost/mysite/about,http://localhost/mysite/contactus等。 我想打电话给那个特定链接的相应页面。 我想的是什么,将页面添加到菜单链接在php

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

当我点击主菜单它去的页面URL像http://localhost/mysite/index.php和有关菜单要http://localhost/mysite/about.php,但我需要的是当我点击关于菜单,它要到该页面网址为http://localhost/mysite/about。没有PHP的扩展,它会进入该页面。

任何帮助,将不胜感激。由于

+0

能否请您详细 – Preethi

+0

使用的.htaccess @Preethi说 – Karthik

回答

0

这两行添加到您的htaccess文件。

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

我希望它有帮助。

+0

感谢你这么多@Stackgeek – Preethi

0

你只需要添加一个.htaccess文件在你的根目录下,并添加下面这样的:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 
0

.htaccess文件影响他们放置的目录和所有子目录

删除扩展

**Add following code inside the .htaccess file:** 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
相关问题