.htaccess URL结构(带有变量)在分页时停止工作

.htaccess URL结构(带有变量)在分页时停止工作,.htaccess,url-rewriting,pagination,rewrite,.htaccess,Url Rewriting,Pagination,Rewrite,我在这两个页面中的一个页面上遇到htaccess问题:index.php&search.php 这两个页面都是功能性的&依赖于通过“GET”方法发送给它们的变量 搜索示例- search.php?tag=keyphase 显示为:site.com/tag/keyphase # HTACCESS: Options +FollowSymlinks RewriteEngine On RewriteRule ^tag/(.*)/?$ /search.php?tag=$1 [NC,L] # inter

我在这两个页面中的一个页面上遇到htaccess问题:index.php&search.php

这两个页面都是功能性的&依赖于通过“GET”方法发送给它们的变量


搜索示例-

search.php?tag=keyphase

显示为:
site.com/tag/keyphase

# HTACCESS:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^tag/(.*)/?$ /search.php?tag=$1 [NC,L]

# internal forward
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tag/(.+?)/?$ /search.php?tag=$1 [L,QSA,NC]

# external rewrite
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search\.php\?tag=([^\s]+) [NC]
RewriteRule ^ /tag/%1? [R=302,L]

索引示例-

index.php?id=id&title=title

显示为:
site.com/cover/TITLE-ID

# HTACCESS:  
RewriteRule ^cover/(.*)-(.*)/?$ index.php?id=$2&title=$1 [NC,L]

# internal forward FOR SINGLE PAGE (index)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cover/(.+?)-(.+?)/?$ /index.php?id=$2&title=$1 [L,QSA,NC]

# external rewrite
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s]+)&title=([^\s]+) [NC]
RewriteRule ^ /cover/%2-%1? [R=302,L]

两个页面都有分页,我的问题是,它只适用于search.php

搜索页面w/分页:
site.com/tag/keyphase&page=#
有效!返回正确的分页结果。

索引页带页码:
site.com/title&page=#-ID
在URL中的title&ID之间插入
&page=#
,但显示结果。


我所看到的这两个变量之间的唯一区别是传递的变量的数量,否则它们将被完全相同地重写


我需要帮助使我的.htaccess结构无缝工作,为我的index.php页面URL使用分页查询字符串。

您需要在内部重写规则中使用
QSA
标志并重新排列规则

保持.htaccess如下所示:

RewriteEngine On

# external rewrite
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^&\s]+)&title=([^&\s]+)&page=([^&\s]+) [NC]
RewriteRule ^ /cover/%2-%1/%3? [R=302,L]

RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^&\s]+)&title=([^&\s]+)\s [NC]
RewriteRule ^ /cover/%2-%1? [R=302,L]

# external rewrite
RewriteCond %{THE_REQUEST} \s/+search\.php\?tag=([^&\s]+)&page=([^&\s]+) [NC]
RewriteRule ^ /tag/%1/%2? [R=302,L]

RewriteCond %{THE_REQUEST} \s/+search\.php\?tag=([^&\s]+)\s [NC]
RewriteRule ^ /tag/%1? [R=302,L]

# internal forward FOR SINGLE PAGE (index)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cover/([^-]+)-([^/]+)/([0-9]+)/?$ /index.php?id=$2&title=$1&page=$3 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cover/([^-]+)-([^/]+)/?$ /index.php?id=$2&title=$1 [L,QSA,NC]

# internal forward
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tag/([^/]+)/?$ /search.php?tag=$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tag/([^/]+)/([0-9]+)/?$ /search.php?tag=$1&page=$2 [L,QSA,NC]

检查更新的规则。确保这些是你仅有的规则。然后尝试以下URL:
site.com/tag/keyphase/2
site.com/tag/keyphase/2
内部变成
site.com/search.php?tag=keyphase&page=2
这不正确吗?要测试注释出
RewriteCond%{THE_REQUEST}\s/+search\.php\?tag=([^&\s]+)&page=([^&\s]+)[NC]
规则。您需要注释的不是这一行吗
RewriteRule^/tag/%1/%2?[R=302,L]
也一样。
当导航被使用两次时
:问题是在您的一侧使用相对URL。确保使用绝对URL,这意味着您必须确保这些文件的路径以
http://
或斜杠
/
开头。当分页不起作用时,您在索引页上看到的确切URL是什么?还告诉什么应该是确切的“内部URL”的索引页面分页。