【问题标题】:Adding pages to menus link in php [duplicate]在php中将页面添加到菜单链接[重复]
【发布时间】:2017-12-27 10:35:30
【问题描述】:

我是 php 的初学者。我正在尝试使用 php 创建一个网站。我有名为 index.php、about.php、contact.php 等的页面。我有一个名为 home、About、Contact 等的菜单。我希望菜单链接应该是这样的http://localhost/mysite/abouthttp://localhost/mysite/contactus、等等.. 我想调用该特定链接的相应页面。 我尝试的是,

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

当我单击主菜单时,它会转到带有http://localhost/mysite/index.php 之类的 URL 的页面,而关于菜单转到 http://localhost/mysite/about.php 但我需要的是当我单击“关于”菜单时,它会转到带有 http://localhost/mysite/about 之类的 URL 的页面.如果没有 php 扩展,它会转到该页面。

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 能不能说详细点
  • 使用 .htaccess @Preethi

标签: php


【解决方案1】:

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

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

我希望它有所帮助。

【讨论】:

  • 非常感谢@Stackgeek
【解决方案2】:

你只需要在你的根目录中添加一个.htaccess 文件,并在其中添加以下内容:

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

【讨论】:

    【解决方案3】:

    .htaccess 文件会影响它们所在的目录和所有子目录

    删除扩展

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-01
      • 2018-08-23
      • 2014-01-12
      • 2011-10-31
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多