重写URL .htaccess或Javascript的一部分?

时间:2014-01-23 17:19:51

标签: javascript .htaccess

我想重写部分网址:

我需要这个:

http://example.com/subdir/form.php?email=sampleemail%40gmail%2com&name%20(awf_first)=John&name%20(awf_last)=Richardson

要改写为:

http://example.com/subdir/form.php?email=sampleemail%40gmail%2com&first_name=John&last_name=Richardson

所以基本上: - name%20(awf_first)重写为first_name - name%20(awf_last)重写为last_name

我尝试使用.htaccess RewriteRule,但它没有用完:

# Enable Rewrite Engine
RewriteEngine on

#Create friendly URL
RewriteRule ^&first_name=$ &name%20(awf_first)= [L]

#Create friendly URL
RewriteRule ^&last_name=$ &name%20(awf_last)= [L]

1 个答案:

答案 0 :(得分:0)

您需要匹配查询字符串:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*)name%20\(awf_first\)(.*)$
RewriteRule ^(.*)$ /$1?%1first_name%2 [L,R,NE]

RewriteCond %{QUERY_STRING} ^(.*)name%20\(awf_last\)(.*)$
RewriteRule ^(.*)$ /$1?%1last_name%2 [L,R,NE]