【问题标题】:How to use mod_rewrite to get pages to appear as page1.html, page2.html etc?如何使用 mod_rewrite 让页面显示为 page1.html、page2.html 等?
【发布时间】:2021-02-17 15:08:43
【问题描述】:

我有以下 5 页:

index.php?id=page1
index.php?id=page2
index.php?id=page3
index.php?id=page4
index.php?id=page5

并想使用 Mod Rewrite 将它们更改为:

page1.html
page2.html

等等……

如何编码?当谈到 .htaccess 文件时,我完全是蓝色的。谢谢。

【问题讨论】:

  • 请在您的问题中添加您尝试过的 htaccess 文件(没有错或对,我们都在这里学习),谢谢。

标签: apache .htaccess


【解决方案1】:

这可能就是你要找的:

RewriteEngine on
RewriteRule ^/?([^.]+)\.html$ /index.php?id=$1 [QSA,END]

为此,您显然需要将重写模块加载到您的 http 服务器中并在其中激活。

GBest 是将这些规则放置在您的 http 服务器的实际主机配置中。如果您无权访问它(因此,如果您使用廉价的托管服务提供商),您可以使用分布式配置文件(“.htaccess”),在这种情况下,需要在内部启用对主机的此类文件的解释http 服务器。

还有一个一般建议:为什么要使用老式的“文件扩展名”?这些天来,这真的没有多大意义。为什么不使用没有的 URL,所以采用 https://example.com/some-page-title 的样式?

【讨论】:

  • 感谢您的回答。关于 qour 问题 - 我在招聘过程中使用这种旧技术,所以我无能为力。
猜你喜欢
  • 1970-01-01
  • 2011-09-09
  • 2013-11-16
  • 2012-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多