Plamen Nikolov
Plamen Nikolov

Reputation: 2733

Rewrite rules for mod_rewrite to mimic virtual directories

I am running a multi-client application without subdomains. I need to stick to using virtual subfolders:

The application itself is located at: example.com/

I need the following address pattern to map to the above address:

example.com/any-valid-string/* -> example.com/* (without redirect)

For example:

example.com/any-valid-string/assets/css/style.css

actually resolves physically to

example.com/assets/css/style.css

I am working now with a hard-coded client name, for example called "sample" this does the trick:

RewriteRule ^sample/?(.*)$ $1 [QSA,NS,L]

I need the "sample" part also dynamic, I tried the following but without success:

RewriteRule ^([^/]+)/?(.*)$ $2 [QSA,NS,L]

Upvotes: 1

Views: 49

Answers (1)

anubhava
anubhava

Reputation: 785541

Try this rule:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^[^/]+(/.*)?$ /$1 [NS,L]

Upvotes: 1

Related Questions