URL重写规则不起作用

时间:2014-06-20 10:56:23

标签: .htaccess url mod-rewrite url-rewriting

当前网址

http://mywebsite.com/explore.php?location=india&search_query=about&filter[]=v

所需网址

http://mywebsite.com/explore/india/about/v

使用的规则:

RewriteRule ^explore/([^/]*)/([^/]*)/([^/]*)$ /explore.php?location=$1&search_query=$2&filter[]=$3 [L]

1 个答案:

答案 0 :(得分:0)

您忘了指定您的字词可以是多个字符。我认为你需要更像的东西:

RewriteEngine on
RewriteRule ^explore/([^/]*)/([^/]*)/([^/]*)$ /explore.php?location=$1&search_query=$2&filter[]=$3 [L]

http://mywebsite.com/explore/india/about/v

如果您在$_GET中输出explore.php,则会获得:

array(3) { 
    ["location"]=> string(5) "india" 
    ["search_query"]=> string(5) "about" 
    ["filter"]=> array(1) { 
        [0]=> string(6) "v" 
    } 
} 

您的实际RewriteRule的工作类似于:

http://mywebsite.com/explore/i/a/v

希望有所帮助