php mod_rewrite

  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

Hi

I'm trying to create tag pages based on one php page that will be re-written to the tag/[tag].html

I'm not a programmer so my question is pretty basic. What I have done until now is to create the tagdetail.php and a call to the tag pages that have this address mydomain .com/tag/[$tag_dash].html (example: mydomain .com/tag/mortgage.html). In addition I have added a this line to the .htaccess file:
RewriteRule ^tag/.*\.html$ tagdetail.php?tag_dash [L]

From what I understand, it looks like the tagdetail.php "doesn't know" it is being called.
What should I add or fix in order that it will be called?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

try the following:
Code: [ Select ]
RewriteRule ^tag/(.*)\.html$ tagdetail.php?tagdash=$1 [L,QSA]
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
try the following:
Code: [ Select ]
RewriteRule ^tag/(.*)\.html$ tagdetail.php?tagdash=$1 [L,QSA]


Thanks.

I get a blank page like I got before (it is not a 404).
It looks like the issue is even before the rewrite. The page is not loading any content at all.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

It's kinda tough for me to say ... do you have code you can show me ... ?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
It's kinda tough for me to say ... do you have code you can show me ... ?

Yes, but I'm not feeling comfortable putting it on a public site. Is there a way I can send you the files?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Well the whole idea behind ozzu is for people to have their questions answered by other people ... it is nice to see examples as I am looking through forum posts so I can implement these examples on my site ...

You can however send me a PM (Private Message) ... I am leaving work now and my internet at home is off because internet in South-Africa is just too rediculously expensive. I will be back tomorrow at 8 AM CAT (+2) - that is 16 hours from now ... and I can try and assist you some time then ...
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

I do understand it and even don't mind that you'll post the relevant code part that is safe to share publically after you'll see it.

Since I have a window of 16 hours until you are back to "internetland" I'll keep trying solving it and update/pm you later.

Your help is much appreciated, thanks
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

I was trying to post the code of two files but since they contain links the forum does not allow it.

I don't want to remove the links in the code since it will hurt the integrity of your inspection.

How can we by pass it?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

what do you mean that the forum doesn't allow links? I thought that was only for the first ten or so posts ... ?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
what do you mean that the forum doesn't allow links? I thought that was only for the first ten or so posts ... ?

When I try to post it says please remove links.
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

assaf wrote:
righteous_trespasser wrote:
what do you mean that the forum doesn't allow links? I thought that was only for the first ten or so posts ... ?

When I try to post it says please remove links.


Oh, I see it is possible to post attachments, so here they are:

Note: At the bottom of every article at RealEstateProArticles .com you'll find the tags. If you'll click on them you'll get a blank page and not the content that is expected. Even if there is a mistake in fetching the data, I still expect to see the top, side nav bars and bottom areas on the page instead of blank.

Please let me know if you need additional information.

Thanks
Attachments:
php files.zip

(2.92 KiB) Downloaded 232 times

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I am looking at it and I don't quite get what is going on in those files ... What are they supposed to do?

And what EXACTLY is the issue you are having ... ?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
I am looking at it and I don't quite get what is going on in those files ... What are they supposed to do?

And what EXACTLY is the issue you are having ... ?


I'm trying to have tags (these are viewable at the bottom of every article on the site).
When clicking on the tags from the article pages I should get (currently) 5 articles that have that specific tag (keyword). The tag page that should be opened is tagdetail.php

Currently, when clicking on a tag (from an article page), all I get is an empty page. Not even the side bars, top etc'
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

on the top of that page add the following (just for debugging):
Code: [ Select ]
<?php error_reporting(E_ALL); ?>

and then see if you get any php errors ...
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
on the top of that page add the following (just for debugging):
Code: [ Select ]
<?php error_reporting(E_ALL); ?>

and then see if you get any php errors ...

Added to tagdetail.php
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

and, did you get any errors?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
and, did you get any errors?

Yes :-)
Here it is
Code: [ Select ]
Notice: Undefined index: tag_dash in /home1/onlineb1/public_html/realestateproarticles/func/tag_det.inc.php on line 2

Notice: Undefined index: tag_dash in /home1/onlineb1/public_html/realestateproarticles/func/tag_det.inc.php on line 6
  1. Notice: Undefined index: tag_dash in /home1/onlineb1/public_html/realestateproarticles/func/tag_det.inc.php on line 2
  2. Notice: Undefined index: tag_dash in /home1/onlineb1/public_html/realestateproarticles/func/tag_det.inc.php on line 6


Where do I define the tag_dash?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

"tag_dash" is a GET variable - it should be part of your url ... What URL are you at when you get these errors?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
"tag_dash" is a GET variable - it should be part of your url ... What URL are you at when you get these errors?

Just found a typo in the .htaccess. Fixed it and now I don't get any error message, just the empty page.

In order to see it, just go to any article page at realestateproarticles(.)com and you'll see at the bottom of the page "Tags (testing!!)". Click on one of the tags.

The url from the clicked tag is a mod_rewrite url that is set in the .htaccess with this line:
Code: [ Select ]
RewriteRule ^tag/(.*)\.html$ tagdetail.php?tag_dash=$1 [L,QSA]
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

I think that the area to concentrate in, is tag_det.inc.php

Line 6 - I think that the check if not numeric is not relevant and even wrong.

Line 16 - I'm not exactly sure what it does or if it checks the right path

What say you?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Oh wait ... obviously ... just remove the following lines of code from tag_det.inc.php ...
Code: [ Select ]
if (!is_numeric ($_REQUEST['tag_dash']))
{
die();
}
  1. if (!is_numeric ($_REQUEST['tag_dash']))
  2. {
  3. die();
  4. }
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

Removed.
Now I get to the "Thank you page" which is supposed to be loaded when the "else" is activated. It means that there is no match in this part:
Code: [ Select ]
if (preg_match ("/^([0-9.,-]+)$/", $blast)) {
   $blast = "true";
  1. if (preg_match ("/^([0-9.,-]+)$/", $blast)) {
  2.    $blast = "true";


How do i fix the syntax of this line to match? The value to match is placed just before .html
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I don't even know why you check that ... but something like this might work ...
Code: [ Select ]
if (preg_match ("/^([a-zA-Z0-9.,-]+)$/", $blast)){
 $blast = "true";
  1. if (preg_match ("/^([a-zA-Z0-9.,-]+)$/", $blast)){
  2.  $blast = "true";
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
I don't even know why you check that ... but something like this might work ...
Code: [ Select ]
if (preg_match ("/^([a-zA-Z0-9.,-]+)$/", $blast)){
 $blast = "true";
  1. if (preg_match ("/^([a-zA-Z0-9.,-]+)$/", $blast)){
  2.  $blast = "true";


That worked and now I have a lot of other errors that I have to start analyze.
Many many many thanks for your great help. I'll do some checking and get back with either questions or update.

Again, thank you very very much.
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

After a little bit of cleaning, now I have to pass this error:

Fatal error: Call to a member function select() on a non-object in...tags_mid_1.php on line 14

tags_mid_1.php :
Code: [ Select ]
<?php

$homearticle = 5 ;


$sql = "SELECT tblarticles.intId AS artid1, tblarticles.intCategory, tblarticles.intAuthorId, tblarticles.intStatus,

tblarticles.textSummary, tblarticles.varArticleTitle, tblauthor.varFirstName, tblauthor.varlastName, tblauthor.intId

FROM `tblarticles`, `tblauthor` where (tblarticles.intStatus = 1 AND tblarticles.intAuthorId = tblauthor.intId AND tblauthor.intStatus = 1 AND tblarticles.varKeywords like '%".$tag."%')

ORDER BY tblarticles.intHit DESC LIMIT 0, $homearticle";

$result1 = $obj_db->select($sql);


?>

<ul style="list-style-image: url(/images/16dot5a.gif);">

<?php

if(isset($result1))

{



foreach ($result1 as $row)

{
$intcat = "";
$intcat = $row['intCategory'];

$sql2 = mysql_query("SELECT varCategory FROM tblcategories WHERE intID = '$intcat'");
$cat1 = mysql_fetch_assoc($sql2);
if($sql2){
$cat_list = "";
$cat_list = stripString($cat1['varCategory']);
}
$art_num = stripString($row['artid1']);
$cat_num = stripString($row['intCategory']);
$art_title = stripString($row['varArticleTitle']);
$auth_idnum = stripString($row['intAuthorId']);
$auth_fname = stripString($row['varFirstName']);
$auth_lname = stripString($row['varlastName']);
$art_sum = stripString($row['textSummary']);

$the_title = _prepare_url_text($art_title);
$the_name = $auth_fname." ".$auth_lname;
$new_name = _prepare_url_text($the_name);
?>

<li><a href="<?php echo $site_URL ?>Art/<? echo $art_num;?>/<? echo $cat_num;?>/<?php echo $the_title ?>.html" title="<? echo $art_title;?>"><h1 class="h1article_title"><? echo $art_title;?></h1></a>&nbsp;<em><font size="1">By:</font></em><a href="<?php echo $site_URL ?>Author/<?php echo $row['intAuthorId'] ?>/<?php echo $new_name; ?>.html"><font size="1"><?php echo $auth_fname." ".$auth_lname; ?></font></a><br><h2 class="h2article_title"><?php echo $art_sum; ?></h2><br>
<font size="1"><b><i>In Category -</i></b> <?php echo $cat_list ;?>

<?php
}

}
?>
  1. <?php
  2. $homearticle = 5 ;
  3. $sql = "SELECT tblarticles.intId AS artid1, tblarticles.intCategory, tblarticles.intAuthorId, tblarticles.intStatus,
  4. tblarticles.textSummary, tblarticles.varArticleTitle, tblauthor.varFirstName, tblauthor.varlastName, tblauthor.intId
  5. FROM `tblarticles`, `tblauthor` where (tblarticles.intStatus = 1 AND tblarticles.intAuthorId = tblauthor.intId AND tblauthor.intStatus = 1 AND tblarticles.varKeywords like '%".$tag."%')
  6. ORDER BY tblarticles.intHit DESC LIMIT 0, $homearticle";
  7. $result1 = $obj_db->select($sql);
  8. ?>
  9. <ul style="list-style-image: url(/images/16dot5a.gif);">
  10. <?php
  11. if(isset($result1))
  12. {
  13. foreach ($result1 as $row)
  14. {
  15. $intcat = "";
  16. $intcat = $row['intCategory'];
  17. $sql2 = mysql_query("SELECT varCategory FROM tblcategories WHERE intID = '$intcat'");
  18. $cat1 = mysql_fetch_assoc($sql2);
  19. if($sql2){
  20. $cat_list = "";
  21. $cat_list = stripString($cat1['varCategory']);
  22. }
  23. $art_num = stripString($row['artid1']);
  24. $cat_num = stripString($row['intCategory']);
  25. $art_title = stripString($row['varArticleTitle']);
  26. $auth_idnum = stripString($row['intAuthorId']);
  27. $auth_fname = stripString($row['varFirstName']);
  28. $auth_lname = stripString($row['varlastName']);
  29. $art_sum = stripString($row['textSummary']);
  30. $the_title = _prepare_url_text($art_title);
  31. $the_name = $auth_fname." ".$auth_lname;
  32. $new_name = _prepare_url_text($the_name);
  33. ?>
  34. <li><a href="<?php echo $site_URL ?>Art/<? echo $art_num;?>/<? echo $cat_num;?>/<?php echo $the_title ?>.html" title="<? echo $art_title;?>"><h1 class="h1article_title"><? echo $art_title;?></h1></a>&nbsp;<em><font size="1">By:</font></em><a href="<?php echo $site_URL ?>Author/<?php echo $row['intAuthorId'] ?>/<?php echo $new_name; ?>.html"><font size="1"><?php echo $auth_fname." ".$auth_lname; ?></font></a><br><h2 class="h2article_title"><?php echo $art_sum; ?></h2><br>
  35. <font size="1"><b><i>In Category -</i></b> <?php echo $cat_list ;?>
  36. <?php
  37. }
  38. }
  39. ?>
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Well, look at what the error is telling you ... Have you checked line 14 ... ?

If you have, you will see that the code on that line is:
PHP Code: [ Select ]
$result1 = $obj_db->select($sql);

It tells you that you are trying to use the variable $obj_db as an object, but it has not been declared as an object ...

With that statement I can see you are trying to run a query using some kind of database/query class. I look just further down your code and there you are running a query without trying to use that class (Line 36).

Try and implement what you see on line 36 on line 14 where the error is.

Looking at this, and at the questions you are asking, I am assuming that you did not code this yourself, and you either took over a project from someone else, or just pasted code from a blog or somewhere without testing it properly. I've got to be honest with you, I don't like helping in situations like these, because through these questions you aren't really learning anything, rather just getting someone else (me) to fix your issues, and that is not what this forum is about at all ... I am not trying to be difficult or rude by saying this, I just don't want to do your work for you without you learning anything from it.
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

righteous_trespasser wrote:
Well, look at what the error is telling you ... Have you checked line 14 ... ?

If you have, you will see that the code on that line is:
PHP Code: [ Select ]
$result1 = $obj_db->select($sql);

It tells you that you are trying to use the variable $obj_db as an object, but it has not been declared as an object ...

With that statement I can see you are trying to run a query using some kind of database/query class. I look just further down your code and there you are running a query without trying to use that class (Line 36).

Try and implement what you see on line 36 on line 14 where the error is.

Looking at this, and at the questions you are asking, I am assuming that you did not code this yourself, and you either took over a project from someone else, or just pasted code from a blog or somewhere without testing it properly. I've got to be honest with you, I don't like helping in situations like these, because through these questions you aren't really learning anything, rather just getting someone else (me) to fix your issues, and that is not what this forum is about at all ... I am not trying to be difficult or rude by saying this, I just don't want to do your work for you without you learning anything from it.


I've stated from the beginning that I'm not a programmer. The entire solution is based on parallel pages within the CMS script of my site. I took existing pages and customized them. It is clearly stated by the CMS developer that I purchased it from that I have full permission to do that.

You are not rude or difficult at all, you are very honest and helpful. I do learn with your assistance and yet I have no intention to be a programmer. As I mentioned before, I highly appreciate your help whether you choose to continue or stop.

Thanks
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Cool stuff ... anyhow, did you come right ... ?
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

Cool.

I've changed this line
Code: [ Select ]
$result1 = $obj_db->select($sql);

To this
Code: [ Select ]
$result1 = mysql_fetch_assoc($sql);


And now I get this message:
Code: [ Select ]
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/onlineb1/public_html/realestateproarticles/func/tags_mid_1.php on line 14


   Warning: Invalid argument supplied for foreach() in /home1/onlineb1/public_html/realestateproarticles/func/tags_mid_1.php on line 29
  1. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/onlineb1/public_html/realestateproarticles/func/tags_mid_1.php on line 14
  2.    Warning: Invalid argument supplied for foreach() in /home1/onlineb1/public_html/realestateproarticles/func/tags_mid_1.php on line 29


So it seems that I have to check what is wrong with the select statement.
  • assaf
  • Beginner
  • Beginner
  • assaf
  • Posts: 40

Post 3+ Months Ago

It seems that the problem was accessing the DB, so I included the config file and brought back this line:
Code: [ Select ]
$result1 = $obj_db->select($sql);

and it sorted it out.

I've checked the select statement on the DB and it works as expected. Now the issue that I'm facing is that the variable $tag is null in tags_mid_1.php so it has no impact on the where condition.

I have to find a way that it will hold the value from the calling page. I tried to add:
Code: [ Select ]
$tag_dash = $_REQUEST['tag_dash'];
$tag = str_replace ("-"," ",$tag_dash);
  1. $tag_dash = $_REQUEST['tag_dash'];
  2. $tag = str_replace ("-"," ",$tag_dash);

but it doesn't seem to work.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 32 posts
  • Users browsing this forum: No registered users and 54 guests
  • 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 post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.