简体   繁体   中英

Creating a regex redirect rule based on parameter in url

I'm trying to create a htaccess 302 redirect rule which should work as follows:

http://domain.com/projects/this_can_be_whatever/identifier_2/identifier_3/

redirect to:

http://domain.com/assignments/identifier_2_identifier_3/

So basically it removes this_can_be_whatever and combines the last two identifiers / folders with an underscore instead of a "/".

Edit: I just noticed that my client has changed the links on their site :( I've updated the URL structure above. Sorry for this.

RewriteEngine on
RewriteRule ^projects/(?:.+)/(.+)/(.+)/$ http://domain.com/assignments/$1_$2/ [R=302,L]

should work

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