$_Get 在这种特殊情况下不起作用

发布于 2024-09-25 02:15:00 字数 353 浏览 3 评论 0原文

我正在尝试使用 http://www.example.com/news/id/21/title/top-10-things/?page=1 用于发送页面参数,但它在下面的 php 中不起作用

是我的.htaccess 文件中的设置

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2
RewriteRule ^news/$ /news.php

I am trying to use
http://www.example.com/news/id/21/title/top-10-things/?page=1 for sending the page parameter and it is not working in php

below is my setting in the .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2
RewriteRule ^news/$ /news.php

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

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

发布评论

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

评论(2

自演自醉 2024-10-02 02:15:00

尝试将 %{QUERY_STRING} 附加到 htaccess 中的网址。

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4&%{QUERY_STRING}
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2&%{QUERY_STRING}
RewriteRule ^news/$ /news.php&%{QUERY_STRING}

正如 Daniel 指出的,您还可以使用 mod_rewrite qsappendQSA 标志来实现此目的。参考: http://httpd.apache.org/docs/2.0/mod/mod_rewrite .html

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

Try appending the %{QUERY_STRING} to the URLs in your htaccess.

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4&%{QUERY_STRING}
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2&%{QUERY_STRING}
RewriteRule ^news/$ /news.php&%{QUERY_STRING}

As Daniel noted, you can also use the mod_rewrite qsappend or QSA flag for this purpose. REF: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]
陌若浮生 2024-10-02 02:15:00

QSA 标志设置为将请求的查询自动附加到替换 URL 中:

RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

此外,如果可以更具体,则不应使用 .*。在这种情况下,使用 [^/]+ 可以避免不必要的回溯:

RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/([^/]+)/([^/]+)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

对于任意数字或参数的通用解决方案,请参阅 重写任意数量的路径段来查询参数

Set the QSA flag to get the requested query automatically appended to the one in substitution URL:

RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

Furthermore, you shouldn’t use .* if you can be more specific. In this case using [^/]+ instead avoids unnecessary backtracking:

RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/([^/]+)/([^/]+)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

And for a general solution for an arbitrary number or parameters, see Rewriting an arbitrary number of path segments to query parameters.

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