How to redirect everything after slash to domain before?

一个人想着一个人 提交于 2020-01-17 05:52:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!