Reputation: 6959
I am using Apache's mod_rewrite module. Is there a way to reference a group captured by RewriteRule
within the regex of RewriteCond
?
For example:
RewriteCond %{REQUEST_URI} ^(.*(?=/#How can I 'paste' $1 = RewriteRule's (.*) group here?#$))
RewriteRule ^(.*)$ - [E=BASE_PATH:%1]
Here I will match the base path of the request URI, for example, if I request mysite.domain/subdir/my/site/dir
, and .htaccess
is inside subdir/
then:
1) RewriteRule ^(.*)$ ----> ^(my/site/dir)$ -----> $1 = my/site/dir
2) RewriteCond /subdir/my/site/dir ^(.*(?=/#I need to 'paste' the $1 RewriteRule's matched group here#$))
How can I do that so that my RewriteCond regex is generated 'dynamically' and becomes:
^(.*(?=/my/site/dir$))
Where my/site/dir is what was matched in RewriteRule's $1 group?
Upvotes: 1
Views: 1889
Reputation: 41249
Not sure I understand your question, but here is a way to get the RewriteBase dyanmically
RewriteEngine on
RewriteCond $1-%{REQUEST_URI} ([^-]*)-(.*?)\1$
RewriteRule ^(.*)$ - [E=BASE:%2]
Your RewriteBase path is now available for use in the env %{ENV:BASE}
Upvotes: 2