I have a file in this format:
from: to:
from: to:
I want to parse the file to give me Apache RewriteRules and RewriteConds where needed.
I can do the first part without stripping out the " part like this:
/^from:/{from = $2}#;if ($1 ~ /\?) uri=true}
/^to:/{to = $2;print "RewriteRule ^"from" "to " [L,R=301]"}
Which results in output like this:
RewriteRule ^ [L,R=301]
which isn't what I need because I need to strip out the beginning up until the first / on the from: line. It also needs to be updated so that when there's a query string it doesn't use the same format as when there isn't one.
The desired output for a line without a query string is this:
RewriteRule ^/tip/1,page [L,R=301]
And with a query string is this:
RewriteCond %{REQUEST_URI} /path/articles/showarticle\.html [NC]
RewriteCond %{QUERY_STRING} id=mycode
RewriteRule ^(.*)$ [L,R=301]
I know for stripping out the characters I can probably use index and substr, but I'm not too sure about how to handle the if portion.
Any help would be appreciated.
Thanks,
John
from: to:
from: to:
I want to parse the file to give me Apache RewriteRules and RewriteConds where needed.
I can do the first part without stripping out the " part like this:
/^from:/{from = $2}#;if ($1 ~ /\?) uri=true}
/^to:/{to = $2;print "RewriteRule ^"from" "to " [L,R=301]"}
Which results in output like this:
RewriteRule ^ [L,R=301]
which isn't what I need because I need to strip out the beginning up until the first / on the from: line. It also needs to be updated so that when there's a query string it doesn't use the same format as when there isn't one.
The desired output for a line without a query string is this:
RewriteRule ^/tip/1,page [L,R=301]
And with a query string is this:
RewriteCond %{REQUEST_URI} /path/articles/showarticle\.html [NC]
RewriteCond %{QUERY_STRING} id=mycode
RewriteRule ^(.*)$ [L,R=301]
I know for stripping out the characters I can probably use index and substr, but I'm not too sure about how to handle the if portion.
Any help would be appreciated.
Thanks,
John