Forum Moderators: coopster & phranque

Message Too Old, No Replies

A discussion on mod_rewrite

         

toolman

5:41 pm on Jul 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been toying with a number of possibilities and I continue to end up using php and mysql. So in order to eliminate the "?" I guess I need a good lesson in mod_rewrite. I've looked at the engleshall papers but I only know enough to get myself in trouble.

What do I need to do to turn dynamic urls into static urls?

theperlyking

6:18 pm on Jul 2, 2001 (gmt 0)

10+ Year Member



perhaps this example will help

#first switch rewriting on
RewriteEngine on
#now rewrite any thing that matches mydomain.com/myscript/scriptparameter.html to mydomain.com/cgi-bin/myscript.cgi?scriptparameters
#rewrite - syntax is rewriterule FROM TO
RewriteRule ^myscript/([0-9a-zA-Z]+).html /cgi-bin/myscript.cgi?$1 [L]

The ([0-9a-zA-Z]+) basically means "match any combination of letters and numbers", whatever is matched is then stored in the variable $1 and used in the real url.

In the above example if someone typed mydomain.com/myscript/blahblah.html the server would actually return mydomain.com/cgi-bin/myscript.cgi?blahblah

Wow now my head hurts :)

mivox

6:35 pm on Jul 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ooh... that's cool... I really need to sit down and learn this stuff...

theperlyking

6:47 pm on Jul 2, 2001 (gmt 0)

10+ Year Member



Yep, very very useful. Its also currently blocking email harvesters and badly behaved proxies for me.

edit: the worst thing about it though is a slight error will take your whole site down with an "Internal Server" error until you fix it, can be pretty hair raising.

toolman

6:59 pm on Jul 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TPK does that make the site spider friendly?

theperlyking

8:11 pm on Jul 2, 2001 (gmt 0)

10+ Year Member



If you mean converting dynamic to static then yes, as far as anyone/anything requesting the page is concerned theres no way of knowing its not really static and my SERP's seem to confirm this.

bartek

12:18 am on Sep 11, 2001 (gmt 0)

10+ Year Member



Suppose I have pages with links like page.htm?print (SSI generated print version). When does the rewrite actually take place? Before the SSI that generates the print version or after it's generated and ready to be displayed? Having a hard time with this one as it appears to mess up the SSI calls. Anyone with ideas?

grnidone

3:15 am on Sep 11, 2001 (gmt 0)



I agree with Mivox,

but isn't the example backwards? Don't you want to go from
url.com/bla?whatever.htm
to
url.com/bla/whatever.htm

?
-G

theperlyking

10:15 am on Sep 11, 2001 (gmt 0)

10+ Year Member



I understand why it looks that way.

The thing to remember is that the real url doesnt change and you are just masking it with a nicer looking one. You are telling mod_Rewrite "when you see the nice url rewrite it to the real url", you are not actually changing the url.

E.g
User types /blah/3 mod rewrites it to /blah.pl?x=3 because /blah.pl?x=3 is the REAL url. In fact the user could still type /blah.pl?x=3 and it would work perfectly.

Hope I make sense :)

4eyes

10:59 am on Sep 11, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



flagged

Thanks your perly highness
This is the first time I (nearly) understood it.

I am sure I will fully understand after a bit of thrashing about with a none sensitive site.

thanks again