如何为网站上的每个页面创建类似 url 的目录
我有一个跨多个页面的内容网站,但只有 1 个 index.php 文件根据页面号从数据库中检索数据。
目前,url 方向必须类似于 domainname.com/Page/content.php?page=3
我注意到,很多网站都有类似目录的 url 结构,例如:
domainname .com/Page/3
我知道如何将其更改为 domainname.com/Page/?page=3
但我希望删除 ?page
部分。
我怎样才能做到这一点,而不需要为每个页面单独创建目录,内容不断增长,因此每个页面都会发生变化。
谢谢
I have a content site that spreads across multiple pages but there is only 1 index.php file which retrieves the data from the database based on the page no.
Currently the url direction has to be something like domainname.com/Page/content.php?page=3
I have noticed, quite a few sites have directory like structure for the urls like:
domainname.com/Page/3
I know how to change it to domainname.com/Page/?page=3
but I am looking to remove the ?page
part.
How can I do this, without individually creating a directory for each page, the content keeps growing, hence changes for each page.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些网站使用 mod_rewrite 使用正则表达式对请求的 URL 进行“重写”
编辑:
将
domainname.com/Page/3
重写为:
domainname.com/Page/content .php?page=3
在
.htaccess
文件中看起来像这样:这里我还对 var 名称做了限制,可以是大写字母或小写字母。
These sites use mod_rewrite to do a "rewrite" on the requested URL using a regular expression
EDIT:
rewriting this:
domainname.com/Page/3
to that:
domainname.com/Page/content.php?page=3
would look like this in the
.htaccess
file:here i also made a restriction for the var name to be a letter either capital or small.
“URL 重写”是执行自定义 URL 结构的功能。这是大多数常见 Web 服务器中非常常见且重要的功能。 URL 重写不仅仅适用于 Apache。例如,
Apache 使用 Mod_Rewrite 模块。
Nginx 使用“Rewrite”和“Try_Files”指令。
Cherokee 具有内置功能,可通过管理 Web 面板进行配置。
还有更多的例子,这些只是我曾经使用过的一些例子。另外,我听说有些项目在编程代码中进行了重写。随着新语言特定网络服务器的出现,这种情况变得更加普遍。
"URL Rewrites" is the feature that performs a custom URL structure. This is a very common and important feature in most common web servers. URL rewrites are not just available with Apache. For example,
Apache uses the Mod_Rewrite Module.
Nginx uses the 'Rewrite' and "Try_Files" directives.
Cherokee has the feature built-in, configurable from admin web panel.
there are many more examples, these are just some I have worked with. In addition, I have heard some projects do the rewrites in the programming code. This has become more prevalent with the new language specific web-servers.