2012-01-05 56 views
0

你怎么会重定向(301?)?:如何查询变量设置成子目录的.htaccess(301重定向)

test.com/?dep=CAR(变量是动态的,以后无论发生什么事=)

到子目录:

test.com/CAR/

这是我到目前为止有:

Options +FollowSymlinks 
RewriteEngine on 

RewriteCond %{QUERY_STRING} ^dep=(.*) 
RewriteRule ^.*/[L,R=301] 

我在localhost(WAMP)上测试这个。
和主目录是本地主机/ newsite/
(本地主机/ newsite /?DEP = CAR)
,但我想这不应该的问题?在线或本地主机。

回答

1

请尝试以下

Options +FollowSymlinks 
RewriteEngine on 
RewriteBase/

#if it has a dep param, capture the value 
RewriteCond %{QUERY_STRING} (^|&)dep=([^&]+) [NC] 
#and redirect to /value/ 
RewriteRule .* /%2/? [L,R=301] 


#if there is no dep param 
RewriteCond %{QUERY_STRING} !dep= [NC] 
#and capture the directory and pass as a dep param 
RewriteRule ^([a-zA-Z]+)/$ ?dep=$1 [L] 
+0

当我尝试这个,我得到的“http://本地主机// DEP = CAR”(我已经更新了更多的信息运算) – Rob 2012-01-05 22:22:08

+0

@Rob固定错字并添加'?'来抑制原始查询字符串 – 2012-01-05 22:39:35

+0

url到达子目录,但是说的是“在此服务器上找不到请求的URL localhost/newsite/CAR /”。 org localhost/newsite /?dep = CAR。 – Rob 2012-01-05 22:53:11