Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Rewrite rule for review.cgi

Quote Reply
Rewrite rule for review.cgi
Hi there,
I've successfully got rewrite rules working for my dynamic site using the following;

.htaccess file in root directory:
RewriteEngine On
RewriteRule ^/?$ /resources/
RewriteRule ^/resources/?$ /resources/

Apache config httpd.conf:
<Directory "/home/myurl/public_html/resources">
Options All -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule (.*) /cgi-bin/page.cgi?g=$1 [L]
AllowOverride All
Allow From All
</Directory>

I'm now trying to do the same for review.cgi and not doing very well. Using code from the forum, I added the following global called review_rewrite;
sub {
my $tags = shift;
my $Title;
$Title .= "$tags->{'Title'}";
$Title =~ y/ \t\r\n?"'#/__/d;
return 'http://www.myurl.com/reviews/' . $Title . '_L' . $tags->{'ID'} . '.html';
}

I then added another .htaccess file into my reviews directory;
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*L([0-9]+).*\html$ /cgi-bin/review.cgi?ID=$1&d=1 [L]

I'm now adding a review link in my templates using this;
<a href="<%review_rewrite%>">Read <%Review_Count%> Reviews</a>

Clicking on the link causes the server to give an error 500.
I think the reason is because I've effectively got two rewrite rules in conflict here.
The first one for the main site clashes with the one for the reviews.

Can anybody help me make sense of how to achieve this?
Quote Reply
Re: [Piers1] Rewrite rule for review.cgi In reply to
Hi,

Personally, I would just put it in your main httpd.conf file. Something like;

RewriteRule ^/reviews/.*L([0-9]+)\.html$ /cgi-bin/review.cgi?ID=$1 [L]

..and then this global;

Code:
sub {
my $ID = $_[0]
my $Title = $_[1];

$Title =~ y/ \t\r\n?"'#/__/d;
return $CFG->{build_root_url} . '/reviews/' . $Title . '_L' . $ID . '.html';
}

Just for the future... when you have;

$Title .= "$tags->{'Title'}";

..you don't actually need the " , or the '. i.e you could just use;

$Title = $tags->{Title};

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Rewrite rule for review.cgi In reply to
OK,

The global bit works - It's generating a URL to a review like this;
http://www.myurl.com/reviews/Link_Title_L1239.html

I've added this into the httpd.conf file (below my existing declaration for page.cgi) and restarted apache;

<Directory "/home/myurl/public_html/reviews">
Options All -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^/reviews/.*L([0-9]+)\.html$ /cgi-bin/review.cgi?ID=$1 [L]
AllowOverride All
Allow From All
</Directory>

Do I still need an .htaccess file in the reviews directory?

I'm getting a file not found error when I click on the link.

Any pointers? - Thanx for your help.

Cheers,
Piers
Quote Reply
Re: [Piers1] Rewrite rule for review.cgi In reply to
Mmm.. did you try "tailing" your error_log?

tail -n20 -f /full/path/to/error_log

Then try calling the page, and see if mod_rewrite is even kicking in (or giving an error). If mod_rewrite doesn't give an error, and you just get a normal 404... then the rule match won't be working right. Not the easist thing to debug (from experience) Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Piers1] Rewrite rule for review.cgi In reply to
Try temporarily changing the [L] to [R] and you should see the URL that it is rewriting in your browser address bar - helps to track down the problem.
Quote Reply
Re: [afinlr] Rewrite rule for review.cgi In reply to
Got it!!

I put the following into an .htaccess file in the reviews directory (I couldn't get it working in apache httpd.conf);
RewriteEngine On
RewriteRule ^.*L([0-9]+).*\html$ /cgi-bin/review.cgi?ID=$1&d=1 [L]

The thing that was stopping it working was having in the .htaccess file;
Options +FollowSymLinks
Removed that and I'm now all good.

Thanks for the help, and I'm glad I stuck with it,

Cheers,

Piers

Now of course I'm all fired up!!!

Is there any way of doing something similar for the list of reviews for each poster??
i.e to rewrite this into something more robot friendly;
<a href='<%db_cgi_url%>/review.cgi?user=<%Review_Owner%>'>

Last edited by:

Piers1: Mar 14, 2005, 12:58 PM
Quote Reply
Re: [Piers1] Rewrite rule for review.cgi In reply to
Hi Piers

Just wanted to thank you for your indications. I also tried out the httpd.conf way and just like you I couldn't figure out what needs to be done but your example of :

RewriteEngine On
RewriteRule ^.*L([0-9]+).*\html$ /perl/review.cgi?ID=$1&d=1 [L]

that I put in the folder "opinions"

using as you stated the following global (I called it "rewrite_review_url") to create the URL that will be caught by the rewrite :

sub {
my $tags = shift;
my $Title;
$Title .= $tags->{'Title'};
$Title =~ y/ \t\r\n?"'#/__/d;
return $CFG->{build_root_url} . '/opinions/' . $Title . '_L' . $tags->{'ID'} . '.html';
}

and placing this in the detailed page for users to view the reviews :
<a href="<%rewrite_review_url%>">See opinions posted about this article</a>

I'd tried using this in the httpd.conf but it had no effect whatsoever Mad :

<Directory /var/home/site_name/opinions>
Options All -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^/opinions/.*L([0-9]+)\.html$ /perl/review.cgi?ID=$1 [L]
AllowOverride All
Allow From All
</Directory>

Anyway as you say and thanks to your help I've got it working for the reviews and I know so little about it that I'm not even sure what advantage there is compared to having it in the httpd.conf ! Wink

Thanks, John
Significant Media