0

I am looking for the way I can use Rewrite Base in htaccess with regular expression.

I have now

RewriteEngine On
RewriteBase /api/v1

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

But I need to have base url as /api/v1 and /api/v2 maybe /api/v3 in the future

How can I achieve this ?

  • I wouldn't do it like this. Think about it. In fact it should be better having a new direcory and rewritten from these new directories the versions of yourt API. – jankal Dec 04 '15 at 23:40
  • I need to do this in the same director that's why I am asking – emldadeg Dec 04 '15 at 23:43
  • I promise you. It'll become very messy having more than one version in one directory. – jankal Dec 04 '15 at 23:44
  • Possible duplicate of [Set RewriteBase to the current folder path dynamically](http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically) – Panama Jack Dec 05 '15 at 19:08

1 Answers1

0

Don't rely on RewriteBase.

If /api/vX is in the URL that got you to this file, just extract it with a rewritecond looking at REQUEST_URI and never make a relative substituton in a rewriterule.

covener
  • 17,402
  • 2
  • 31
  • 45