Search code examples
regex.htaccessurlmod-rewriteurl-rewriting

mod rewrite path in url


I would like to rewrite with the .htaccess-file in root directory the internal path example.com/app/app-v1/ (including all subdirectories) to example.com/app/in the url, so that everything in the /app-v1/ folder is right behind the /app/ directory in the url.

I tried

RewriteEngine On
Redirect /app/app-v1/ /app/ 

but that's not working


Solution

  • You may try this code in site root .htaccess:

    RewriteEngine On
    
    RewriteRule ^app/((?!app-v1/).*)$ app/app-v1/$1 [NC,L]
    

    (?!app-v1/) is a negative lookahead to avoid rewriting URI starting with /app/app-v1/ to this rule.