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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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 用3个参数重写Mod?_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 用3个参数重写Mod?

.htaccess 用3个参数重写Mod?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我用了很多方法来找出如何重写这个mod,但是O完全没有成功 我需要使用以下方法重写的.htaccess代码: /apple/uncoming/2→ /handler.php?topic=apple&orderby=comming&page=2 这很容易做到,但问题是不需要所有参数,因此链接每次都有不同级别的参数,如下所示: /apple/popular/2→ /handler.php?topic=apple&orderby=popular&page=2 /apple/2→ /handler

我用了很多方法来找出如何重写这个mod,但是O完全没有成功

我需要使用以下方法重写的.htaccess代码:

  • /apple/uncoming/2
    /handler.php?topic=apple&orderby=comming&page=2
这很容易做到,但问题是不需要所有参数,因此链接每次都有不同级别的参数,如下所示:

  • /apple/popular/2
    /handler.php?topic=apple&orderby=popular&page=2
  • /apple/2
    /handler.php?topic=apple&orderby=&page=2
  • /all/popular/2
    /handler.php?topic=all&orderby=popular&page=2
  • /apple/comming/
    /handler.php?topic=apple&orderby=comming&page=
简而言之,URL在一个静态顺序中有3个可选参数:(topic)(orderby)(page)

注意:ORDERBY参数可以是“popular”或“uncoming”或“nothing”


谢谢

我建议将域名(/apple/comming/2)后的所有内容重定向到index.php,然后使用php解析url并调用相应的函数。

这应该可以:

RewriteRule     ^([0-9]*)/?$ handler.php?topic=&orderby=&page=$1 [L]
RewriteRule     ^(upcoming|popular)/([0-9]*)/?$ handler.php?topic=&orderby=$1&page=$2 [L]
RewriteRule     ^([^/]*)/([0-9]*)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule     ^([^/]*)/(upcoming|popular)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule     ^([^/]*)/(upcoming|popular)/([0-9]*)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]
RewriteRule     ^([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule     ^([^/]+)/([^/]+)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule     ^([^/]+)/([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]

您只需按照首选顺序声明重写即可。

对于您在上面提供的情况,这些规则应该有效:

RewriteRule     ^([0-9]*)/?$ handler.php?topic=&orderby=&page=$1 [L]
RewriteRule     ^(upcoming|popular)/([0-9]*)/?$ handler.php?topic=&orderby=$1&page=$2 [L]
RewriteRule     ^([^/]*)/([0-9]*)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule     ^([^/]*)/(upcoming|popular)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule     ^([^/]*)/(upcoming|popular)/([0-9]*)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]
RewriteRule     ^([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule     ^([^/]+)/([^/]+)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule     ^([^/]+)/([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]

+1您不能使用mod rewrite在没有查询的情况下重写url。是否有modrewrite代码将域名后的所有内容重定向到handler.php?everything=XXXX?thanks@Sandeep班萨尔:那完全错了。您确实可以使用mod_rewrite重写每个请求,而无需触摸查询。