Apache rewrite rule different if capture is empty

前提是你 提交于 2019-12-13 05:40:38

问题


what I have so far is:

<VirtualHost 111.111.111.111:80>
     ServerName ex.me
     ServerAlias www.ex.me

     Options +FollowSymLinks
     RewriteEngine on
     RewriteRule ^/(.*)$  http://exemple.com/foo/$1 [R=301,L]
</VirtualHost>

what I need is if (.*) is empty, it rewrites to http://exemple.com and if it has something, it redirects to http://exemple.com/foo/$1 -- I don't know how to do the if empty rule. right now. Right now it redirects to http://exemple.com/foo/ no matter if there is something captured or not.

Thanks for your help


回答1:


 RewriteRule ^/$  http://exemple.com/ [R=301,L]
 RewriteRule ^/(.+)$  http://exemple.com/foo/$1 [R=301,L]


来源:https://stackoverflow.com/questions/5466456/apache-rewrite-rule-different-if-capture-is-empty

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