我知道“东西”的第 2 页很可能有 www.website.com/stuff/2 而不是 www.website.com/stuff/page?=2。我该怎么做呢?我不知道要搜索什么。
编辑说我正在使用 PHP 和 $_GET 来获取参数。这是如此广泛使用,所以我不认为这会很困难。
There are 3 common ways:
Rewrite the URL internally from .../2
to .../?page=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.
Have the web program capture all URLs and use routing to determine which function to call and what values to pass it.
这完全取决于您使用的是什么。
PHP ? 我相信您正在寻找 apache .htaccess URL 重写
是的,在您的 .htaccess 中使用简单的 mod_rewrite 规则很有可能。通过启用 mod_rewrite 和 .htaccess httpd.conf
,然后将此代码放在您.htaccess
的DOCUMENT_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]