Reputation: 28284
I have this condition and rule and want to know what actually is going on here
RewriteCond %{REQUEST_URI} ^/sitepages/newversion/
RewriteCond %{QUERY_STRING} ^(.*[?|&])page=dynamicpage
RewriteRule ^sitepages/newversion/(.*)$ /pages/oldversion/$1 [L]
Also very interested in a detail explaination of this line
RewriteRule ^sitepages/newversion/(.*)$ /pages/oldversion/$1 [L]
thanks
Upvotes: 0
Views: 26
Reputation: 836
RewriteCond %{REQUEST_URI} ^/sitepages/newversion/
If the request URL starts with "/sitepages/newversion/",
RewriteCond %{QUERY_STRING} ^(.*[?|&])page=dynamicpage
and the query string contains "page=dynamicpage",
RewriteRule ^sitepages/newversion/(.*)$ /pages/oldversion/$1 [L]
then take the part of the URL after "sitepages/newversion/" and redirect the request to "/pages/oldversion/(the rest of the url)".
For example:
http://domain.com/sitepages/newversion/someleaf?page=dynamicpage
will get redirected to
http://domain.com/pages/oldversion/someleaf?page=dynamicpage
Upvotes: 1
Reputation: 784918
First of all your rule can be rewritten better as this:
RewriteCond %{QUERY_STRING} (?:^|&)page=dynamicpage(?:&|$) [NC]
RewriteRule ^sitepages/newversion/(.*)$ /pages/oldversion/$1 [L,NC]
Now for explanation part.
RewriteCond
is matching a URI with query parameter page=dynamicpage
RewriteRule
is matching a URI with pattern sitepages/newversion/(.*)$
which will match /sitepages/newversion/abc123
or /sitepages/newversion/foobar
(.*)
is capturing group to populate $1
with the value abc123
in my first example./pages/oldversion/$1
that will become /pages/oldversion/abc123
for same example.NC
flag is for no case comparison.L
flag is for Last
that makes mod_rewrite
run the rewrite loop again.Upvotes: 1