SunQuest
           Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 29th, 2001, 03:45 PM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
mod_rewrite => It doesn't pass my variables from page to page.

Environment:
Kernel/2.4.2-2
Apache/1.3.19
Distro/RH7.1

.htaccess-file:
RewriteEngine On
RewriteRule ^news/([0-9]+) news.php?nid=$1 [T=application/x-httpd-php]
RewriteRule ^news$ index.php

MySQL query:
$result = mysql_query("SELECT * FROM news where nid = '$nid'");

What I'm trying to do:
On the front page, there's a box with news, wich contains a synopsis, and reader will have to press a "read more" link to get the rest. Before I came across mod_rewrite I used news.php?nid=$nid, but now I want to use news/$nid - I've gotten the page to work with all images and such displaying as they should. But the variable $nid isn't passed through to the news.php page where I display the rest of the news... I've tried to echo out $nid and it comes out blank. Please help?

Reply With Quote
  #2  
Old October 29th, 2001, 09:32 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RewriteEngine On
RewriteRule ^news/([0-9]+)$ /server/path/to/news.php?nid=$1 [T=application/x-httpd-php,L]
RewriteRule ^news/?$ index.php [R,L]

Reply With Quote
  #3  
Old October 29th, 2001, 11:20 PM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
Unhappy

Nope.. still not working

Reply With Quote
  #4  
Old October 30th, 2001, 04:13 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
1) Where is your index.php?
2) Where is your .htaccess?
3) Do you have write access to httpd.conf?

>> still not working
4) What page did you get in return?

Reply With Quote
  #5  
Old October 30th, 2001, 04:19 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
>> 1) Where is your index.php?

In the same folder where news.php is
/www/htdocs/adfS/www.hypothetic.net/index.php news.php

>> 2) Where is your .htaccess?
/www/htdocs/adfS/www.hypothetic.net/.htaccess

>> 3) Do you have write access to httpd.conf?
Yes

>> 4) What page did you get in return?
news.php without the news. I've also
added echo ("blah $nid"); so that I can see if $nid is true..

Reply With Quote
  #6  
Old October 30th, 2001, 05:46 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Remove the 2nd RewriteRule line.

Just use:

RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

Since you have access to httpd.conf, why don't you do all this in <Directory "/www/htdocs/adfS/www.hypothetic.net"> ?

You also can enable RewriteLog like so:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9

Reply With Quote
  #7  
Old October 30th, 2001, 05:56 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
>> Remove the 2nd RewriteRule line.
Done

>> Just use: RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]
Done

>> Since you have access to httpd.conf, why don't you do all this in <Directory "/www/htdocs/adfS/www.hypothetic.net"> ?
Done (didn't know that was a way)

>> You also can enable RewriteLog like so:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9
Tried that, got an error stating that RewriteLog wasnt allowed there.

Reply With Quote
  #8  
Old October 30th, 2001, 06:12 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Tried that, got an error stating that RewriteLog wasnt allowed there

Define the following lines globally:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9

Within the <Directory> block, put:

RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

BTW, the ruleset should work and there is no need to enable RewriteLog.

Reply With Quote
  #9  
Old October 30th, 2001, 06:28 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
Quote:
Define the following lines globally:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9
Done
Quote:
Within the <Directory> block, put:

RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]
Done
Quote:
BTW, the ruleset should work and there is no need to enable RewriteLog. [/B]
Hmm.. perhaps I've installed it wrong..
I just recompiled apache with --enable-module=most...
And restarted it..

Do you have ICQ or something? irc maybe...?
It'll be alot easier that way..

If you won't display yours, I can just display mine;
ICQ: 108045292
irc: sam\ @ EFnet

Anyway, this is the logfile created:
http://www.hypothetic.net/rewrite_log - It's kinda long so I posted the file instead.. hope you don't mind.

Last edited by sam54 : October 30th, 2001 at 06:32 AM.

Reply With Quote
  #10  
Old October 30th, 2001, 07:12 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You need to put the Rewrite lines within <Directory> of the actual file system path, no symlink. That said, this path:

/www/htdocs/adfS/www.hypothetic.net

can't be symlink.

All you need to do is to access it like http://www.hypothetic.net/news/123, which matches news/([0-9]+)$, then it will take 123 to $1.

Here is what the rewrite log should look like:

add path-info postfix: /www/htdocs/adfS/www.hypothetic.net/news -> /www/htdocs/adfS/www.hypothetic.net/news/123
strip per-dir prefix: /www/htdocs/adfS/www.hypothetic.net/news/123 -> news/123
applying pattern '^news/([0-9]+)$' to uri 'news/123'
rewrite news/123 -> /www/htdocs/adfS/www.hypothetic.net/news.php?nid=123
news.php?nid=123 -> uri=/www/htdocs/adfS/www.hypothetic.net/news.php, args=nid=123
remember /www/htdocs/adfS/www.hypothetic.net/news.php to have MIME-type 'application/x-httpd-php'
strip document_root prefix: /www/htdocs/adfS/www.hypothetic.net/news.php -> /news.php
internal redirect with /news.php [INTERNAL REDIRECT]

You also can do a search under my username with the keyword RewriteRule in this forum. I have posted many examples for your situation.

In the rewrite_log that you posted, the lines are too far off and nowhere near. You need to check and make sure the paths are correct. I suggest you start off with another file name like news1.php instead of news.php. In news1.php, just put something simple like so:

<?php
echo $QUERY_STRING;
?>

Last edited by freebsd : October 30th, 2001 at 07:18 AM.

Reply With Quote
  #11  
Old October 30th, 2001, 07:18 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
Quote:
You need to put the Rewrite lines within <Directory> of the actual file system path, no symlink. That said, this path:

/www/htdocs/adfS/www.hypothetic.net

can't be symlink.
I'm sorry, I don't understand what you mean by this.. perhaps you can provide me with an example?

Quote:
You also can do a search under my username with the keyword RewriteRule in this forum. I have posted many examples for your situation.
That I will do. Thanks for your patience and quick responses.

Reply With Quote
  #12  
Old October 30th, 2001, 07:25 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> perhaps you can provide me with an example?

I posted so many examples that I can't even remember which one would be appropriate. Check this one out (a little more complicated than yours) ->
http://forums.devshed.com/showthrea...ght=RewriteRule

Reply With Quote
  #13  
Old October 30th, 2001, 07:31 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
Hmm.. I ment an example on what should be in httpd.conf...
This is what I have now:

RewriteEngine on
RewriteLog /www/logs/rewrite_log
RewriteLogLevel 9

<Directory "/www/htdocs/adfS/www.hypothetic.net">
RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>

I figure there's something wrong since it doesn't work.. maybe you know what?

Reply With Quote
  #14  
Old October 30th, 2001, 07:43 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Comparing your rewrite_log with mine (I posted in my previos post), it appears that you have set your path incorrectly right at the strip per-dir prefix line.
Whenever you see a Passthru, that means the pattern doesn't match. Therefore, yours never reached rewrite news/123 line.

Please use a new php script like news1.php so you can see what's going on easier.

BTW, if you don't know what MultiViews is for, don't enable it. Maybe when you are accessing http://www.hypothetic.net/news and Apache think it should be www.hypothetic.net/news.php and automatically append the php extension. So mod_rewrite didn't go further enough and passthru.

MultiViews had many critical exploits in the past, even in 1.3.20. In 1.3.22, MultiViews is broken.

Last edited by freebsd : October 30th, 2001 at 07:46 AM.

Reply With Quote
  #15  
Old October 30th, 2001, 07:54 AM
sam54 sam54 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Tromso, Norway
Posts: 10 sam54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to sam54
Quote:
BTW, if you don't know what MultiViews is for, don't enable it. Maybe when you are accessing http://www.hypothetic.net/news and Apache think it should be www.hypothetic.net/news.php and automatically append the php extension. So mod_rewrite didn't go further enough and passthru.

MultiViews had many critical exploits in the past, even in 1.3.20. In 1.3.22, MultiViews is broken.
Yeah! I removed MultiViews and it worked! I didn't know what it was for, but it was on another <Directory> section... Anyway, thanks alot for your patience in this matter!

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > mod_rewrite => It doesn't pass my variables from page to page.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump