Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 与.htaccess重写URL冲突的问题_Apache_.htaccess_Rewrite - Fatal编程技术网

Apache 与.htaccess重写URL冲突的问题

Apache 与.htaccess重写URL冲突的问题,apache,.htaccess,rewrite,Apache,.htaccess,Rewrite,好的,这是我的.htaccess,位于http://example.com/forums/ RewriteEngine On RewriteRule ^threads/([^/]+)/([^/]+)$ forums-threads.php?code=$1&pn=$2 [QSA] RewriteRule ^threads/([^/]+)$ forums-threads.php?code=$1 [QSA] RewriteRule ^new-thread/([^/]+)$ forums-ne

好的,这是我的.htaccess,位于
http://example.com/forums/

RewriteEngine On 
RewriteRule ^threads/([^/]+)/([^/]+)$ forums-threads.php?code=$1&pn=$2 [QSA]
RewriteRule ^threads/([^/]+)$ forums-threads.php?code=$1 [QSA]
RewriteRule ^new-thread/([^/]+)$ forums-new-thread.php?code=$1 [QSA]
RewriteRule ^new-post/([^/]+)$ forums-new-post.php?code=$1 [QSA]
RewriteRule ^([^/]+)/([^/]+)$ index.php?code=$1&pn=$2 [QSA]
RewriteRule ^([^/]+)$ index.php?code=$1 [QSA]
现在的问题是,当我转到一个新的线程URL时,它会转到索引页面,并且输出的
$\u GET
变量是

Array ( [code] => eUjJP-Announcements [pn] => eUjJP-Announcements )

我想知道如何解决这个问题,以及上面的
.htaccess
代码中是否有任何其他问题需要纠正

之所以发生这种情况,是因为下面的后续规则仍在执行,因为您没有任何其他条件来阻止它

将代码替换为以下内容:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /forums/

RewriteRule \.php$ - [L]

RewriteRule ^threads/([^/]+)/([^/]+)$ forums-threads.php?code=$1&pn=$2 [QSA,L]
RewriteRule ^threads/([^/]+)$ forums-threads.php?code=$1 [QSA,L]
RewriteRule ^new-thread/([^/]+)$ forums-new-thread.php?code=$1 [QSA,L]
RewriteRule ^new-post/([^/]+)$ forums-new-post.php?code=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?code=$1&pn=$2 [QSA,L]
RewriteRule ^([^/]+)$ index.php?code=$1 [QSA,L]

我不得不删除
RewriteBase/
,因为它位于/forums/目录中。不是根。我用我现在拥有的代码替换了你给我的代码,只是一直重定向到同一个页面,并且$\u GET变量的输出是
Array([code]=>index.php)
你没有在问题中提供这个细节(/forums)。我做了一个编辑,现在试试。哦,我不知道我忘了。我道歉。我再次替换了代码,现在当我转到/forums/中的index.php页面时,它会不断刷新/重定向到该页面,$\u GET变量会说
数组([code]=>[L])
如果你转到
example.com/index.php?code=forums
它是否正确加载了论坛?是的,很抱歉,我忘记在索引中添加导致此问题的内容。有一个新的问题出现了。每当我访问index.php时,它只会转到index.php,其中$\u GET变量为
Array([code]=>eUjJP公告)