Troubleshooting URL-Rewrite blues

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Mon Feb 05, 2007 6:46 am    Post subject: Troubleshooting URL-Rewrite blues Reply with quote

I hope that in the future we can temporarily enable/disable URL-rewriting en masse, and without removing any established rewrite rule. I am trying to pin down why one of my PHP scripts doesn't work anymore. It appears that the URL-rewrite system may have something to do with it. This wasn't the case before - as I remember. Seeing now that I have more than 10 rewrite rules established already, I wouldn't want to erase them all just to see if my wayward PHP script works without the URL-rewrite system turned on - and then put them back altogether again.

Actually, this is my situation. I have an alias named /shared pointing to I:\shared. My HTTP doc root is located elsewhere. I also have a CMS located in my doc root and it utilizes these catch-all rewrite rules:
^(.*)\?page=(.*)$ Perform an internal redirection /index.php?q=$1&page=$2 Stop matching
^(.*)$ Perform an internal redirection /index.php?q=$1 Stop matching

Essentially, I would not want any rewrite rules applied on anything that begins with /shared. So I put this rewrite rule before the two rules above:
^\/shared(.*)$ Perform an internal redirection /shared$1 Stop matching

Everything works out... as I thought it would. Until one PHP script residing in /shared caught my eye:
/shared/fun_liners/image_rotator.php

/shared/fun_liners/ is a browsable directory. So when I click on the link to image_rotator.php, the script returns "No input file specified." Hello there, I thought. This didn't happen before URL-rewrite came into play, and that script had been used and has been confirmed to work a thousand times before. So I appended "?q=quotes.gif" in the address bar of my browser in an attempt to see what happens - boom! Abyss gives me the default page-not-found-file output of my CMS. That's when I suspected that this shouldn't be happening. There may be some bugs in Abyss here.

I also tried these other combinations:
/shared/fun_liners/image_rotator.php?q=quotes.gif
/shared/fun_liners/image_rotator.php/quotes.gif
/shared/fun_liners/image_rotator.php/x

Curiously, they either returned "No input file specified" or the default 404 page of my CMS. The funny thing is that when I click on /shared/fun_liners/image_rotator.php
as it has been linked from
/shared/fun_liners/
it gives me a "No input file specified" result. Whereas if I directly type in
/shared/fun_liners/image_rotator.php
or
/shared/fun_liners/image_rotator.php/x
at the address bar of my browser, it gives me the default 404 page of my CMS.

Hmmm... what's going on? And the saga continues...
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Mon Feb 05, 2007 11:46 pm    Post subject: Re: Troubleshooting URL-Rewrite blues Reply with quote

loloyd wrote:
I hope that in the future we can temporarily enable/disable URL-rewriting en masse


Agreed.
Here's a hack to get around that issue.

Stop the Abyss host (:cry:). Backup your abyss.conf file. (To change the configuration manually, the host must be stopped.) Find <urlrewrite><rules> and delete everything until </rules>. Then restart the host. There will be no URL rewriting until you restore the backup.
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Mon Feb 05, 2007 11:57 pm    Post subject: Reply with quote

On another note...

Did you type this in wrong? ^\/shared(.*)$
Maybe it should be ^/shared(.*)
There's no need for the dollar sign to terminate an indefinite string. :)
Also, you don't need to escape the /.

Quote:
/shared/fun_liners/ is a browsable directory. So when I click on the link to image_rotator.php, the script returns "No input file specified."


Solution #1:
Sounds to me like a relative filepath issue. Make the input file in image_rotator.php an absolute path.
I've had this petty problem before with URL rewriting and relative paths.

Solution #2:
Add a condition to your catch-all rules.
Variable: REQUEST_URI
Operator: Does not match with
Regular Expression: ^/shared
(untick case-sensitive)

And then delete your "shared" URL rewrite rule.
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Tue Feb 06, 2007 10:44 am    Post subject: Reply with quote

This post became a duplicate after an Internal Server Error. Please remove this post, if you can. Thank you and sorry for the bother.
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.


Last edited by loloyd on Tue Feb 06, 2007 10:47 am; edited 1 time in total
Back to top View user's profile Send private message Visit poster's website
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Tue Feb 06, 2007 10:46 am    Post subject: Reply with quote

pkSML wrote:
Here's a hack to get around that issue.

Stop the Abyss host (:cry:). Backup your abyss.conf file. (To change the configuration manually, the host must be stopped.) Find <urlrewrite><rules> and delete everything until </rules>. Then restart the host. There will be no URL rewriting until you restore the backup.
Yep. Thanks for the reminder. But I deleted until </urlrewrite> instead of just </rules>. Anyways, having done that, hahaha the PHP script still wouldn't work. So, we can now say it's the scripts' fault. Hmm... I wonder why that is when the script works well in Apache HTTPd. Btw, the script I'm using here is the image rotator from http://alistapart.com/articles/randomizer/.

pkSML wrote:
Did you type this in wrong? ^\/shared(.*)$
Maybe it should be ^/shared(.*)
There's no need for the dollar sign to terminate an indefinite string. :)
Also, you don't need to escape the /.
I tried the no escaping route initially before but it didn't work. So I was left to using the escaped version ^\/shared(.*)$.

Re: the terminator signal, there may be some esoteric reasons for this which may not be obvious to us for now. So I just followed what has been prescribed by experts form Drupal to always put that terminator flag in. Experience has taught me that "esotericity" plays quite a big role in logic sciences. It's a lesson I learned from distinguishing the difference between requesting /subpath and /subpath/ from any kind of webserver. Notice that the extra / from the latter expression means a bundle especially in Unix-based boxes.

pkSML wrote:
Solution #1:
Sounds to me like a relative filepath issue. Make the input file in image_rotator.php an absolute path.
I've had this petty problem before with URL rewriting and relative paths.
You may have something here. I think this would explain why there are two different outputs for different methods of querying (typing in the address bar vs. link-clicked from a directory listing).

pkSML wrote:
Solution #2:
Add a condition to your catch-all rules.
Variable: REQUEST_URI
Operator: Does not match with
Regular Expression: ^/shared
(untick case-sensitive)
Hey! This works in minimizing/simplifying my rewrite rules! But I changed the Regular Expression to ^\/shared(.*)$. I'll be doing this to my other aliases. I'll check if this also solves my original problem and get back with the results.

Thanks for the insights, pkSML. You're really a valuable asset here in the forums :-D.

Anyways, I have tried another route before trying Solution#2 method mentioned above. I created my own PHP script snippet that essentially does the same thing, but without Drupal messing up with results caching. Here it is:

Code:
<?php
//<img src="/shared/fun_liners/image_rotator.php?q=quotes.gif" />
function randomImage ( $array ) {
  $total = count($array);
  $call = rand(0,$total-1);
  return $array[$call];
}
$my_images = array ();
echo '<br />';
$path = "I://shared//fun_liners";
$open = opendir ($path);
while ($file = readdir ($open)) {
  if (eregi("..." . ".gif$" , "$file")) array_push($my_images, "/shared/fun_liners/$file");
}
//while (list($xxxkeyxxx,$xxxvaluexxx) = each($my_images)) {
//  echo "$xxxkeyxxx : $xxxvaluexxx<br />";
//}
echo '<img src="'.randomImage($my_images).'" alt="Random Quote" />';
echo '<br />There are currently '.count($my_images).' possible quotes in the library.';
?>
Note: comments have been left for easy troubleshooting.

An almost equivalent sample output of this code can be viewed at the top of http://loloyd.com/ (but this doesn't run on Abyss, mind you, although my office LAN machine uses the same snippet and it runs on Abyss!). The 1st generated image is from image_rotator.php while the next two are from the script snippet above.
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Tue Feb 06, 2007 4:59 pm    Post subject: Reply with quote

Funny. Guess what, pkSML. In the quite new topic http://www.aprelium.com/forum/viewtopic.php?t=10033
your proposed Solution #2 was already discussed! Back then, I may have had problems with using the terminator flag as well. Oh well...
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Wed Feb 07, 2007 7:22 am    Post subject: Reply with quote

OK, after a modified Solution #2 has been applied, the outputs remained basically the same.

From /shared/fun_liners/
the link to image_rotator.php
returns "No input file specified."

Typing /shared/fun_liners/image_rotator.php directly to the address bar and clicking the Enter key produces... "Error 500 Internal Server Error".

:-D

I can now lay this issue to rest. And let it be for the moment.
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group