Remove part of a URL

安稳与你 提交于 2020-01-02 04:37:26

问题


How can I remove main/ in http://domain/main/about

so the URL will be like this http://domain/about

Thanks


回答1:


Well, in the absence of any further details, you could try something like this:

RewriteRule (.*)/main/(.*) $1/$2

But this is a VERY broad rule - you'd probably want to tune it more tightly than that. Try turning the RewriteLogLevel to 9 and watching the rules as they get processed so you can get a better idea of what is being matched.




回答2:


If you only need one file to be rewritten :

RewriteRule main/about about [L]

or else the TML answer is good :

RewriteRule (.*)/main/(.*) $1/$2 [L]

It rewrites any URL with a /main (even in third, fourth, ... places) in it to prefix/suffix URL.



来源:https://stackoverflow.com/questions/5800203/remove-part-of-a-url

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