2014-01-23 83 views
1

我想重寫URL的一部分:重寫部分URL .htaccess或Javascript?

我需要這樣的:

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 

所以基本上: - 名稱%20(awf_first)改寫成名字 - 名稱%20(awf_last)重寫爲姓氏

我嘗試使用.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] 

回答

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]