0

我知道“东西”的第 2 页很可能有 www.website.com/stuff/2 而不是 www.website.com/stuff/page?=2。我该怎么做呢?我不知道要搜索什么。

编辑说我正在使用 PHP 和 $_GET 来获取参数。这是如此广泛使用,所以我不认为这会很困难。

4

3 回答 3

2

There are 3 common ways:

  1. Rewrite the URL internally from .../2 to .../?page=2.

  2. Use the "path info" mechanism of your web language. A script at /stuff/index.xyz would have a path info of 2 with the given URL.

  3. Have the web program capture all URLs and use routing to determine which function to call and what values to pass it.

于 2013-06-10T00:02:40.990 回答
1

这完全取决于您使用的是什么。

PHP ? 我相信您正在寻找 apache .htaccess URL 重写

于 2013-06-09T23:59:30.507 回答
0

是的,在您的 .htaccess 中使用简单的 mod_rewrite 规则很有可能。通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(stuff)/([^/]+)/?$ /$1.php?page=$2 [L,QSA,NC]
于 2013-06-10T01:38:07.650 回答