Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Php 如何编写'';关于.htaccess_Php_.htaccess - Fatal编程技术网

Php 如何编写'';关于.htaccess

Php 如何编写'';关于.htaccess,php,.htaccess,Php,.htaccess,我希望使用.htaccess转发url categoryname?page=23&sort=alpha to category.php?name=catgoryname&page=23&sort=alpha 但是我无法使用字符?编写重写规则,我尝试使用\?,但总是有一些问题,它不起作用。查询字符串必须在重写条件中匹配,而不是在重写规则中匹配。然后使用[QSA]将现有查询字符串以及新的名称=参数附加到重写的请求上 RewriteEngine On # If both pa

我希望使用.htaccess转发url

categoryname?page=23&sort=alpha to category.php?name=catgoryname&page=23&sort=alpha

但是我无法使用字符
编写重写规则,我尝试使用
\?
,但总是有一些问题,它不起作用。

查询字符串必须在
重写条件
中匹配,而不是在
重写规则
中匹配。然后使用
[QSA]
将现有查询字符串以及新的
名称=
参数附加到重写的请求上

RewriteEngine On
# If both page=, sort= *must* be present
RewriteCond %{QUERY_STRING} page=(\d+)
RewriteCond %{QUERY_STRING} sort=([a-z]+)
# Rewrite categoryname (or other string) into category.php
RewriteRule ^(.+) category.php?name=$1 [L,QSA]
只有当
page=
sort=
都存在时,上述规则才会匹配。如果重写
categoryname
时不需要出现它们,则可以省略这两个
RewriteCond

# If the page= and sort= are not *required*, omit them.
RewriteEngine On
# Rewrite categoryname (or other string) into category.php
RewriteRule ^(.+) category.php?name=$1 [L,QSA]

谢谢,现在我发现了一个新问题,还有一些其他页面有另一个重写规则,我想保留它们,如果链接是其中之一,那么您编写的规则不应该执行,因为之前有一个规则,有解决方案吗?我终于找到了原因,这是我的错:)重写规则^([a-Za-z0-9-]+)\?页面=(.*)排序=(.*)php?name=$1和page=$2和sort=$3