Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite with variables

trying to pass variables to the rewritten page from the original URL

         

pathfinder

12:43 am on Jun 19, 2007 (gmt 0)

10+ Year Member



hi, I was hoping that someone could help me with a rewrite rule. I have used isapi (IIS) rewrite and know my way through what i need to do but I'm having a hard time with mod_rewrite.
My old isapi/IIS based rule is:

RewriteRule /([^/]+)/q/([^/]+).htm /redirect_other.asp\?sid1=$1&Card=$2 [I,L]

so domainname.com/blah/q/1111.htm gets passed to redirect_other.asp with sid1 = blah and Card = 1111

on my /redirect_other.asp i want to be able to display the 2 variables with response.write or pass it to another string.

for mod_rewrite i have tried a few versions of this:

RewriteRule ^(.*)/q/(.*).htm$ /redirect_other.asp\?sid1=%1&Card=%2 [L]

or

RewriteRule ^([^/]+)/q/([^/]+).htm$ /redirect_other.asp?sid1=%1&EbayAuctionID=%2 [L]

It loads the redirect_other.asp page but the variables do not appear to be passed along to this page. additionally other variables that i define on redirect_other.asp like <% this_domain_name = "milliondollarbucket.info" %> do not appear when i use
<%
response.write this_domain_name
%>

This is on a hosted box and i do not have access to any logging.

what am I doing wrong?

thanks

jdMorgan

1:32 am on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your ISAPI Rewrite rule was closer than you thought. The correct code for mod_rewrite would be:

RewriteRule ^[b]([^/]+)/q/([^.]+)\.h[/b]tm$ /redirect_other.asp\?sid1=[b]$1[/b]&Card=[b]$2[/b] [L]

%1 and %2-%9 can be used, but these variables back-reference values from the previously-matched RewriteCond. $1 through $9 refer to matched values in the RewriteRule.

Jim

pathfinder

2:10 am on Jun 19, 2007 (gmt 0)

10+ Year Member



Thanks for the very fast reply!

I tried that and still can't get any variables to render on screen.
here is a basic test page that i am using to see what is being passed.

.htaccess
RewriteEngine on
RewriteRule ^([^/]+)/p/([^.]+)\.htm$ /test.asp\?sid1=$1&Card=$2 [L]

test.asp
<%
this_domain_name = "example.com"
CardID = request.querystring("Card")
sid = request.querystring("sid1")
%>

<HTML><HEAD><TITLE>test <%=this_domain_name%></TITLE>
hello
<%
response.write this_domain_name <BR> CardID <BR>sid
%>
</html>

all I get is a page that says "hello" with "test <%=this_domain_name%>" in the title bar. I have used request.querystring on my IIS server without issue but what am i missing here on this unix/apache server?

[edited by: jdMorgan at 3:38 am (utc) on June 19, 2007]
[edit reason] example.com [/edit]

jdMorgan

3:37 am on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll probably need to use Apache variable names, such as QUERY_STRING; You can ask in the WebmasterWorld PHP forum if you're not sure of how to use them.

Jim