.htaccess 用3个参数重写Mod?
我用了很多方法来找出如何重写这个mod,但是O完全没有成功 我需要使用以下方法重写的.htaccess代码:.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
→/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=
谢谢我建议将域名(/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重写每个请求,而无需触摸查询。