简体   繁体   中英

Rewrite Part of URL .htaccess or Javascript?

I want to rewrite part of url:

I need this:

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

To be rewritten to:

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

So basically: - name%20(awf_first) rewrites into first_name - name%20(awf_last) rewrites into last_name

I tried with .htaccess RewriteRule but it didn't work out:

# 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]

You need to match against the query string for this:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM