1

大家好,我现在一直在工作,$_GET['whatever']这次我需要一些我在看到这个 URL 之前从未做过的事情,domain.com/author/name_of_user我的问题是我如何在那种 URL 中获取数据?我一直在寻找答案,他们所说的只是$_GET[''];所以示例我有这个链接http://localhost/domain/attachments.php 我如何http://localhost/domain/attachments/首先将这个链接更改为?我将如何从中获取数据$_GET['']?请帮帮我我真的很困惑

4

4 回答 4

5

这称为 URL 重写:

http://httpd.apache.org/docs/2.2/rewrite/

http://www.iis.net/downloads/microsoft/url-rewrite

这些是 Apache / IIS 中 url 重写的链接。

简而言之,它需要:http://localhost/domain/attachments.php并将其“转换”(或重写)为 http://localhost/domain/attachments(或您喜欢的任何内容)。

通常它用于改善搜索引擎优化。

你仍然可以正常使用 $_GET 因为它只是一个转换,最后你仍然有whatever.php?var=value&....只是它对浏览器的显示不同。

于 2012-11-26T09:10:47.830 回答
3

重写 URL 非常简单。Apache 附带了一个名为mod_rewrite处理此问题的 mod。你唯一需要做的就是在你的.htaccess.

我推荐你阅读这篇文章:htaccess Tricks

于 2012-11-26T09:10:28.823 回答
2

您将需要 .htaccess 文件位于您网站的根目录,该文件会将您的网站 URL 从 example.com/index.php?var1=12&var2=23 重写为类似于 example.com/pagename/12/23 以下是一些基础知识使用 .htaccess 进行 URL 重写:http ://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

于 2012-11-26T12:26:54.830 回答
2

您应该使用 Apache 的重写模块来重写您的 URL。

在您的特定情况下 - 在您激活之后mod_rewrite- 尝试此重写规则:

RewriteEngine On
RewriteRule ^domain/attachments/?$ /domain/attachments.php

但是,这不会$_GET以任何方式影响您的阵列。

于 2012-11-26T09:10:16.743 回答