Closed Thread Icon

Preserved Topic: mod_rewrite oddity (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21155" title="Pages that link to Preserved Topic: mod_rewrite oddity (Page 1 of 1)" rel="nofollow" >Preserved Topic: mod_rewrite oddity <span class="small">(Page 1 of 1)</span>\

 
Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-08-2002 16:14

Now I use this to produce a printer friendly page:

quote:
RewriteRule print/(.*) /print.php?url=$1 [L]
RewriteRule print_all/(.*) /print.php?url=$1&mode=all [L]



so:

/print/my_dir/something_else/

would make a print-friendly version of the page that lives at:

/my_dir/something_else/

i.e. $url = "/my_dir/something_else/"

Now the second line works perfectly but the first one just won't recognise the $url. I have tried to use this again and just taking the second line of code and slightly adapted it and it fails to work again. Is there anything obviously wrong there or do I need something more sophisticated?

___________________
Emps

FAQs: Emperor

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-08-2002 21:29

The first line doesn't work because filename of the script is the same as imaginary folder which is used as rule. Just rename the name of script to something like "printer_friendly.php" and everything should work fine...

BTW Something is probably wrong with mod_rewrite, because you specified "print/" as rewrite rule (notice the slash at the end), and that is not the same as "print.php", because the first part of filename is ending with a dot, and therefore there should be no infinite loop problems. It should work, but apparently for some reason it doesn't (unless you change first part of rewrite rule and script name). On the other hand if you specified "print(.*)" as rewrite rule (without slash), Apache would go into infinite loop (it will try to rewrite again to print.php and so on)...


Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-08-2002 22:08

mr.maX: Thanks that works a treat (of course).

I'm not sure what you mean in the second part. I have, whilst fiddling, managed to get it into a infinite loop by leaving out the slash but everything is as I want it at the moment - I am doing away with PHP file extensions so:
www.mysite.com/print/something/another/

maps to:
www.mysite.com/print_friendly.php?url=something/another/

If there is a problem then let me know and I'll see what can be done.

Thanks again.

___________________
Emps

FAQs: Emperor

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-08-2002 22:18

The second part of my message from above says that your code should work - I don't see a reason why it doesn't work, apparently mod_rewrite thinks that base of rewrite rule and filename are the same (and rewrites back), but they really aren't "print/" is not the same as "print." (notice slash and dot)...




[This message has been edited by mr.maX (edited 07-08-2002).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-08-2002 22:55

mr.maX: OK cool - although it shouldn't work in theory it does which is fine by me

Thanks again for the help.

___________________
Emps

FAQs: Emperor

« BackwardsOnwards »

Show Forum Drop Down Menu