问题
This is what I'm trying to do:
I want example.com/car/{whatever} redirected to example.com/{whatever}.
For example, example.com/car/honda should be redirected to example.com/honda
BUT if there is nothing after /car/, then just leave it as that.
How can i do that in .htaccess ?
回答1:
Removing a prefix from a URL is pretty simple, just
RewriteRule ^car/(.*)$ /$1 [R,L]
In order to keep a special case, you must put it in front
RewriteRule ^car/$ - [L]
This rule says, if there is just car/ leave it alone, see RewriteRule substitution.
来源:https://stackoverflow.com/questions/40430698/how-to-redirect-everything-after-slash-to-domain-before