Forum Moderators: phranque

Message Too Old, No Replies

How to grab the end of url before redirect.

add end of url to redirect url

         

tommytx

1:24 am on Mar 7, 2006 (gmt 0)

10+ Year Member



Can some of you experts tell me how to grab the end of the url (specifically the file name.) before the redirect acts. For example I want to do the following:

options all
RewriteEngine on
RewriteBase /
RewriteRule rocky /joeboy/index.php

Now I want to add something like the following to the line above.
RewriteRule rocky /joeboy/index.php?$1

Is there a command like the above?$1 that I can add to get the original html file name to tack onto the url before it redirects.

The whole story follows:
When someone types in the url [mysite.com...]

I want the rocky to cause it to forward to /joeboy/index.php but I want to attach the monitor.htm to the query_string somehow so that I can extract it to see what the original url was.

So the forwarding url needs to look something like /joeboy/index.php?monitor.htm

Can I follow the index.php with a?*1 or %1 or $1 or something to grab the original file name and attach it to the redirect url.

When it arrives I want the php file to be able to look at something like the query_string or anything and know what the original requested file was named. That way I could send the visitor to the original file if desired or to someplace else if I choose.

Hope all this makes sense. I know there are some really complicated commands for htaccess and this should be an easy one, but I have no idea what it is and have tried a lot of ideas.

Thanks in advance.

jatar_k

1:28 am on Mar 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since you mentioned php you could do all of this with php

when the original page is hit you could grab whatever you want to tack on the end and issue a header redirect to your other page

jdMorgan

1:44 am on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is called a "back-reference"

RewriteRule ^rocky/(.*)$ /joeboy/index.php?$1 [L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

tommytx

1:48 am on Mar 7, 2006 (gmt 0)

10+ Year Member



Thanks for the input, but that would require conversion of thousands of html pages to php or tell it to treat the html as php. I am looking for one central point to monitor every single request coming into that specific rocky directory, then send them to a special location if they do not qualify, but in some cases, I want to give them the actual page they are requesting.
Bottom line, what I am doing is if they qualify I want to just use a simple include to send then the page requested and if they do not qualify, send the somewhere else.

For example every one requesting any of a thousand files in that directory will be screened by php. Say for example the php pulls out the original file name and places it into $go. I then have a command that says if you qualify you get the command include($go); other wise you get the command include("pissoff.htm");

Problem is, the redirect seems to strip all traces of the orginal file name. Isn't there some way to capture it with all the fancy commands in htaccess?
And append it to the /newdir/index.php?orig.htm

tommytx

1:51 am on Mar 7, 2006 (gmt 0)

10+ Year Member



Thanks Jim,
I just read your post. It looks like just what I am looking for. I am studying it now to see if I can fully understand it. I will test it and let you know. Thanks again for both your quick responses. Oh by the way I have studied a lot at the apachee web, and am having a hard time understanding it. YOu simple report should be easy for me to understand. Thanks a lot. The response above was before I say your response.

tommytx

2:03 am on Mar 7, 2006 (gmt 0)

10+ Year Member



Jim,
You are #*$!hot.

I spent I guess a hundred hours or more printing and reading tons of pages from the apachee website and never could figure out how to do this simple task. Acutally nothing is simple if you don't know how to do it.
I cannot thank you enough.

Thank you! Thank you! Thank you! Thank you! Thank you! Thank you!

Now this is a time when you don't mind if a site has a donation jar out.

Also thanks to the other gentleman who offered help, even though it was not exactly what I was looking for, any help or assistance is always appreciated.

P.S.
Hey I am previewing and that is kinda neat how it removes the expletives it don't like but you still get the idea. Where I was talking about the hot thing in the first line.

tommytx

2:08 am on Mar 7, 2006 (gmt 0)

10+ Year Member



jatar_k,
I can certainly understand how your idea would work for me, but I don't want to have to convert all my pages to php nor add the few lines of code to thousands of pages and they grow every day.
Also I can take this idea to any directory that I have by adding to only the htaccess file and any directory that i place just the one line of code in the htacccess file now does the same task.
This is really #*$! hot.
But thanks again anyway.
Tom

[edited by: jatar_k at 2:13 am (utc) on Mar. 7, 2006]

jatar_k

2:12 am on Mar 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I knew Jim would have your apache answer but I just threw that out there since you mentioned php and there are always a million ways to do things

and yes, Jim is #*$!hot ;)