【问题标题】:Website pages with slashes带有斜线的网站页面
【发布时间】:2012-05-29 19:44:20
【问题描述】:

只是使用 php 建立一个网站。我想知道如何创建页面而不必为每个页面创建“.php”链接。例如,我想将站点构建如下:www.mysite.com/products 而不是 www.mysite.com/products.php。 (更多示例 www.mysite.com/products/headphones)

我正在寻找的一个例子如下:http://www.starbucks.ca/store-locator

知道星巴克是如何做到这一点的吗?它不是为每个页面创建一个单独的文件夹和索引吗?

提前致谢!

杰森

【问题讨论】:

    标签: .htaccess web


    【解决方案1】:

    您可以使用 URL 重写来执行此操作。您可以创建一个.htaccess 文件,将其放在您网站的根目录下,内容如下(例如):

    RewriteEngine On
    RewriteRule ^tutorial/([0-9]+)/$ index.php?tutorial=$1
    RewriteRule ^page/store-locator/$ index.php?page=store-locator
    RewriteRule ^$ index.php
    

    这些是一些基本规则,它们告诉 Web 服务器将没有 .php 的 URL 重写为有 .php 的 URL。

    在上面的例子中,当你访问 example.com/tutorial/3/ 时,它实际上会访问 example.com/index.php?tutorial=3,然后你的 index.php 将显示内容。商店定位器页面也是如此。

    【讨论】:

      猜你喜欢
      • 2012-02-16
      • 2013-08-21
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多