.htaccess &和 %26 都拆分 $_GET

发布于 2024-09-25 00:42:10 字数 1335 浏览 7 评论 0原文

下面是我针对这个特定文章文件夹的 .htaccess 文件。我的问题是,这些 url 在被 php 脚本接收时都分割了 $_GET 变量。

  1. /food-and-diet/articles/test-&-cake.html
  2. /food-and-diet/articles/test-%26-cake.html

这两个网址都会创建这个 $_GET 数组:

Array ( [article] => test- [-cake] => [folder] => none )

Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /food-and-diet/
    RewriteRule ^.+(/css/.+)$ $1 [L]
    RewriteRule ^.+(/js/.+)$ $1 [L]
    RewriteRule ^.+(/images/.+)$ $1 [L]
    RewriteRule ^\index.html$ index.php [NC,L]
    Rewriterule ^articles/?$ index.php?index=$1&article=none&folder=none [NC,L]
    Rewriterule ^articles/([^.^/]+)/?$ index.php?article=none&folder=$1 [NC,L]
    RewriteRule ^articles/([^/]+)\.jpg$ articles/$1.jpg [L]
    RewriteRule ^articles/([^/]+)\.gif$ articles/$1.gif [L]
    RewriteRule ^articles/([^/]+)\.png$ articles/$1.png [L]
    Rewriterule ^articles/([^/]+)\.html$ index.php?article=$1&folder=none [NC,L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.jpg$ articles/$1/$2.jpg [L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.gif$ articles/$1/$2.gif [L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.png$ articles/$1/$2.png [L]
    Rewriterule ^articles/([^.^/]+)/([^/]+)\.html$ index.php?article=$2&folder=$1 [NC,L]

Below is my .htaccess file for this particular articles folder. My problem is that these urls both split the $_GET variable when received by the php script.

  1. /food-and-diet/articles/test-&-cake.html
  2. /food-and-diet/articles/test-%26-cake.html

Both of these urls create this $_GET array:

Array ( [article] => test- [-cake] => [folder] => none )

Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /food-and-diet/
    RewriteRule ^.+(/css/.+)$ $1 [L]
    RewriteRule ^.+(/js/.+)$ $1 [L]
    RewriteRule ^.+(/images/.+)$ $1 [L]
    RewriteRule ^\index.html$ index.php [NC,L]
    Rewriterule ^articles/?$ index.php?index=$1&article=none&folder=none [NC,L]
    Rewriterule ^articles/([^.^/]+)/?$ index.php?article=none&folder=$1 [NC,L]
    RewriteRule ^articles/([^/]+)\.jpg$ articles/$1.jpg [L]
    RewriteRule ^articles/([^/]+)\.gif$ articles/$1.gif [L]
    RewriteRule ^articles/([^/]+)\.png$ articles/$1.png [L]
    Rewriterule ^articles/([^/]+)\.html$ index.php?article=$1&folder=none [NC,L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.jpg$ articles/$1/$2.jpg [L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.gif$ articles/$1/$2.gif [L]
    RewriteRule ^articles/([^.^/]+)/([^/]+)\.png$ articles/$1/$2.png [L]
    Rewriterule ^articles/([^.^/]+)/([^/]+)\.html$ index.php?article=$2&folder=$1 [NC,L]

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

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

发布评论

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

评论(1

吻泪 2024-10-02 00:42:10

正确使用 B 标志将匹配的路径部分转义为查询部分。

Use the B flag to properly escape a matched path part into a query part.

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