Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess htaccess:rewrite/?page=x到/page/x_.htaccess - Fatal编程技术网

.htaccess htaccess:rewrite/?page=x到/page/x

.htaccess htaccess:rewrite/?page=x到/page/x,.htaccess,.htaccess,我的网站URL如下所示: http://site.com/category/?page=1 我想成为: http://site.com/category/page/1 我使用以下代码: RewriteEngine On RewriteRule ^page/(.*)/$ /?page=$1 但是不行。我想这应该是 RewriteEngine On RewriteRule ^category/page/(.*) /category/?page=$1 因为如果你写^page/(.*)/$你会说

我的网站URL如下所示:

http://site.com/category/?page=1
我想成为:

http://site.com/category/page/1
我使用以下代码:

RewriteEngine On
RewriteRule ^page/(.*)/$ /?page=$1

但是不行。

我想这应该是

RewriteEngine On
RewriteRule ^category/page/(.*) /category/?page=$1
因为如果你写
^page/(.*)/$
你会说:我的URL必须以page(而不是category)开头,后面有一个斜杠,就像这样

http://site.com/page/1/
^
标记字符串的开头,
$
标记字符串的结尾)

编辑

对于您的wordpress问题:

RewriteEngine On
RewriteRule ^category/page/(.*) /category/?page=$1 [L]

RewriteRule [...wordpress rules...]

不工作,我的根目录中有WordPress,可能是这导致了问题?是的,这是一个问题。您可以尝试将您的特定规则放在
.htaccess
的顶部,添加一个
[L]标志(在行尾),然后让wordpress规则显示在下面。您将为您的规则赋予更高的优先级,[L]标志告诉apache这是最后一条规则(它不会解释下一条规则)。@NuLLeR注意worpress还有一个强大的重写url的工具:如果您要重定向的页面是wordpress页面,只需打开“否”而不是wordpress页面,它的WordPress插件可以创建动态分页,我测试了你的新代码,但仍然不起作用。如果这是一个插件,你可以使用WP_Rewrite上的WordPress挂钩来定义新规则: