Can mod_rewrite keep the double slash?

I am just looking into mod_rewrite and regex files and what I am trying to do is pass variables of any name with any number of variables and values ​​to a script and forward them to another script.

here is what I have so far:

RewriteEngine on
RewriteRule ^script\$(.*[\])? anotherscript?ip=%{REMOTE_ADDR}&$1 [L] 

      

This seems to work, except that one of the parameters I pass is a url and // after http: // is always separated by one forward slash.

for example i do

script $ url = http://www.stackoverflow.com

then it redirects to:

anotherscript f = 127.0.0.1 & url = http: /www.stackoverflow.com

and the second script chokes on a single shot.

I understand that storing double slashes is the exact opposite of what people usually do with mod_rewrite. Is there a way to keep the double slash?

EDIT . The solution was found using Gumbo.

RewriteCond %{THE_REQUEST} ^GET\ (.*)/script\$([^\s]+) 
RewriteRule ^script\$(.*) anotherscript?ip=%{REMOTE_ADDR}&%2 [L]

      

I had to add this (. *) Before the / script on RewriteCond, once I did it it got rid of 404 errors and then it's just a matter of passing matches.

+1


a source to share


2 answers


Try the following rule:

RewriteCond %{THE_REQUEST} ^GET\ /script\$([^\s]+)
RewriteRule ^script\$.+ anotherscript?ip=%{REMOTE_ADDR}&%1 [L]

      



See Diggbar modrewrite. How do they pass URLs through modrewrite? for an explanation.

+2


a source


I think there might be something wrong with the first part of your RewriteRule

^script\$(.*[\])?

      

The backslash ( \

) is used to exclude the special character in the liter, so you are actually trying to match the closing parenthesis ( ]

) that is intended?



try it

RewriteRule ^script\$(.*)? anotherscript?ip=%{REMOTE_ADDR}&$1 [L]

      

+1


a source







All Articles