简体   繁体   中英

.htaccess replace question marks and slashes from URL

I'm trying to do this by using .htaccess

Redirect: http://example.com/en/signup?type=something

To: http://example.com/snapshots/en_signup_type=something.html

Basically, convert all slashes and question marks to underscores and appending .html .

I found out how to do, there are actually a few more steps than I thought.

  1. Replace all slashes with underscores, RewriteRule ^(.*)\\/(.*)$ $1_$2 [R=301,L] , based on the number of slashes we have, it will redirect the same amount of times, one redirection will convert one slash to one underscore.

http://example.com/en/signup?type=something -> http://example.com/en_signup?type=something

  1. Convert the query string (change question mark to underscore)

RewriteRule ^(.*)$ http://example.com/snapshots/$1_%{QUERY_STRING}.html? [P,L]

The question mark after .html is to prevent the query string to be appended again.

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