|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? ![]() |
|
#2
|
|||
|
|||
|
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] |
|
#3
|
|||
|
|||
|
Nope.. still not working
![]() |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
>> 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.. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
>> 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. |
|
#8
|
|||
|
|||
|
>> 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. |
|
#9
|
|||||
|
|||||
|
Quote:
Quote:
Quote:
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. |
|
#10
|
|||
|
|||
|
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. |
|
#11
|
||||
|
||||
|
Quote:
Quote:
|
|
#12
|
|||
|
|||
|
>> 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 |
|
#13
|
|||
|
|||
|
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? |
|
#14
|
|||
|
|||
|
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. |
|
#15
|
|||
|
|||
|
Quote:
|
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > mod_rewrite => It doesn't pass my variables from page to page. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|