简体   繁体   中英

.htaccess Redirect 301 any subdirectory to a different url from main path

I'm not regex expert and I'm failing on what it looks like a simple task:

I need to 301 redirect urls like this:

/en/example/ www.example.com/hello-world/

/en/example/ANYTHING www.example.com/foobar/

the only way I can think of it is like that

/en/example/(.+) www.example.com/foobar/

but this is overriding the other rule and I'm not able to redirect "/en/example/" on a separate url.

You need to have 2 separate rules for this. First the specific one and then the general one.

RewriteRule ^en/example/?$ /hello-world/ [L,NC]

RewriteRule ^en/example/(.+?)/?$ /foobar/ [L,NC]

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