Apache Mod_rewrite:规则集在重写日志中导致奇怪的拆分和追加

Apache Mod_rewrite:规则集在重写日志中导致奇怪的拆分和追加,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,是什么导致查询字符串被拆分?是什么 导致在第二次运行时追加/news/50(作为下一个标志N的效果) 我所追求的行为是将/about/news/50/重写为/about/news/news item?post\u id=50。 我添加了N标志,因为我想将重写的uri/about/news/news item?post_id=50发送到index.php 我的.htaccess文件中有以下规则: <IfModule mod_rewrite.c> RewriteEngine On Rew

是什么导致查询字符串被拆分?是什么 导致在第二次运行时追加
/news/50
(作为下一个标志
N
的效果)

我所追求的行为是将
/about/news/50/
重写为
/about/news/news item?post\u id=50
。 我添加了
N
标志,因为我想将重写的uri
/about/news/news item?post_id=50
发送到index.php

我的.htaccess文件中有以下规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule ^about/news/(\d+)/$ /about/news/news-item?post_id=$1 [QSA,N]

RewriteRule ^index\.php$ - [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [QSA,L]
</IfModule>
如果您重写的URL已从中删除路径信息,并且不希望重新添加,请尝试DPI(放弃路径信息标志)。这是每个目录重写的问题

编辑:如果你这样做,因为wordpress计算路径信息,你实际上必须重写到/index.php/about/news/。。。让下一轮仍能看到路径信息

重写规则^about/news/(\d+)/$/index.php/about/news/news item?post_id=$1[DPI,L] 而不是

重写规则^about/news/(\d+)/$index.php[DPI,L]

(2) init rewrite engine with requested uri /about/news/50/
(1) pass through /about/news/50/
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/'
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/'
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '^about/news/(\d+)/$' to uri 'about/news/50/'
(2) rewrite 'about/news/50/' -> '/about/news/news-item?post_id=50'
(3) split uri=/about/news/news-item?post_id=50 -> uri=/about/news/news-item, args=post_id=50
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '^about/news/(\d+)/$' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '^index\.php$' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '.' to uri '/about/news/news-item/news/50/'
(4) RewriteCond: input='/about/news/news-item' pattern='!-f' => matched
(4) RewriteCond: input='/about/news/news-item' pattern='!-d' => matched
(2) rewrite '/about/news/news-item/news/50/' -> '/index.php'
(2) trying to replace prefix /wordpress/ with /
(1) internal redirect with /index.php [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /index.php
(1) pass through /index.php
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '^about/news/(\d+)/$' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '^index\.php$' to uri 'index.php'
(1) pass through /wordpress/index.php