htaccess重写规则“页码”问题

发布于 2024-09-09 12:09:34 字数 381 浏览 2 评论 0原文

我已将 .htaccess 文件添加到我的根文件夹中,以便将动态 URL 重写为静态 URL。这似乎已成功完成,但我遇到页码问题。

例如,如果您要访问静态页面 /widgets,则产品的首页很好......但后续页面显示为 /products.php?cat=27&我想要的是后续页面采用 /widgets-pg2/widgets?pg=2 的形式。

以下是我用于初始类别页面的重写规则:-

RewriteRule ^widgets$ products.php?cat=27

如果你们中的任何一位专家可以提供帮助,我们将不胜感激。

I've added a .htaccess file to my root folder for the purposes of rewriting dynamic URLs into static ones. This seems to have been done successfully but I am having problems with page numbers.

For example, if you were to visit a static page /widgets, the first page of the products is fine....but subsequent pages show up as /products.php?cat=27&pg=2 etc. What I want is for subsequent pages to be in the form of /widgets-pg2 or /widgets?pg=2.

Below is my rewrite rule that I used for the initial category page:-

RewriteRule ^widgets$ products.php?cat=27

If any of you experts can help with this, it would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

掀纱窥君容 2024-09-16 12:09:37

我尝试了以下操作,但当我转到 /widgets 时,结果出现“404 Not Found”错误:-

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

我尝试了以下操作:-

RewriteRule ^widgets$ products.php?cat=27 [QSA]

这工作正常,但要转到小部件页面的第二页,我需要输入浏览器:-

/widgets?pg=2

但实际的“第 2 页”链接仍然会导致:-

products.php?cat=27&pg=2

所以除了重写规则之外......也许我需要一个单独的重定向规则?或者可能需要更改页码链接。但由于这些是动态生成的,我不知道如何做到这一点。

以下是该页面的 PHP 代码:- http://freetexthost.com/3ubiydspzm

I tried the following but it resulted in a '404 Not Found' error when I go to /widgets:-

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

And I tried the following:-

RewriteRule ^widgets$ products.php?cat=27 [QSA]

This worked correctly but to go to page two of the widgets page, I need to type in the browser:-

/widgets?pg=2

But the actual 'page 2' link still leads to:-

products.php?cat=27&pg=2

So apart from a rewrite rule....maybe I need a separate redirection rule? Or maybe need to change the page number links. But since these are dynamically generated, I'm not sure how to do this.

The following is the PHP code for the page:- http://freetexthost.com/3ubiydspzm

三生殊途 2024-09-16 12:09:36

尝试

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

之后,转到此处 :)

Try

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

After that, go here :)

好久不见√ 2024-09-16 12:09:36

要允许在重写的 URL 后使用查询字符串,请使用 [QSA] 标志:

RewriteRule ^widgets$ products.php?cat=27 [QSA]

链接将是:

http://example.org/widgets?pg=167&perpage=100&tralala=Hi!

To allow a query string after your rewritten URL use the [QSA] flag:

RewriteRule ^widgets$ products.php?cat=27 [QSA]

A link would than be:

http://example.org/widgets?pg=167&perpage=100&tralala=Hi!
孤星 2024-09-16 12:09:35

你期待猫也会改变吗?您还需要在 URL 中考虑到这一点:

例如 www.site.com/widgets/27/2 可以重写为:

RewriteRule ^widgets/([0-9]+)/([0-9]+)$ products.php?cat=$1&pg=$2

如果小部件始终是 cat 27 那么您可以将其更改为:

RewriteRule ^widgets$ products.php?cat=27 [QSA] 

这是查询字符串附加

Are you expecting the cat to change as well? You'd need to account for that in your URL as well:

e.g. www.site.com/widgets/27/2 could be rewritten as:

RewriteRule ^widgets/([0-9]+)/([0-9]+)$ products.php?cat=$1&pg=$2

If widgets will always be cat 27 then you can change it to:

RewriteRule ^widgets$ products.php?cat=27 [QSA] 

which is query string append

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文