Go Back   Cyber Tech Help Support Forums > Software > Web Development & Graphic Design

Notices

Reply
 
Topic Tools
  #1  
Old July 17th, 2006, 12:47 AM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
Unhappy mod rewrite and php problems

hi all
I can't get this mod rewrite thingy to work with my site

Strange thing is my little test script works, but it wont work with my main wallpaper outputting system (full of bugs probably but I wrote it myself from scratch and i'm proud of it ok )

ok so here is the htaccess in full:
Code:
# error pages
ErrorDocument 404 /404error.htm
ErrorDocument 403 /403error.htm
#rewrite download urls
Options +FollowSymlinks

RewriteEngine on
RewriteRule ^c96/(.+) /wallpapers/cars96/$1 [nc]
RewriteRule ^c101/(.+) /wallpapers/cars101/$1 [nc]
RewriteRule ^c120/(.+) /wallpapers/cars120/$1 [nc]
RewriteRule ^c128/(.+) /wallpapers/cars128/$1 [nc]
RewriteRule ^c160/(.+) /wallpapers/cars160/$1 [nc]
RewriteRule ^c174/(.+) /wallpapers/cars174/$1 [nc]
RewriteRule ^c176/(.+) /wallpapers/cars176/$1 [nc]
RewriteRule ^c240/(.+) /wallpapers/cars240/$1 [nc]

RewriteRule ^f96/(.+) /wallpapers/flags96/$1 [nc]
RewriteRule ^f101/(.+) /wallpapers/flags101/$1 [nc]
RewriteRule ^f120/(.+) /wallpapers/flags120/$1 [nc]
RewriteRule ^f128/(.+) /wallpapers/flags128/$1 [nc]
RewriteRule ^f160/(.+) /wallpapers/flags160/$1 [nc]
RewriteRule ^f174/(.+) /wallpapers/flags174/$1 [nc]
RewriteRule ^f176/(.+) /wallpapers/flags176/$1 [nc]
RewriteRule ^f240/(.+) /wallpapers/flags240/$1 [nc]

RewriteRule ^m96/(.+) /wallpapers/misc96/$1 [nc]
RewriteRule ^m101/(.+) /wallpapers/misc101/$1 [nc]
RewriteRule ^m120/(.+) /wallpapers/misc120/$1 [nc]
RewriteRule ^m128/(.+) /wallpapers/misc128/$1 [nc]
RewriteRule ^m160/(.+) /wallpapers/misc160/$1 [nc]
RewriteRule ^m174/(.+) /wallpapers/misc174/$1 [nc]
RewriteRule ^m176/(.+) /wallpapers/misc176/$1 [nc]
RewriteRule ^m240/(.+) /wallpapers/misc240/$1 [nc]

RewriteRule ^t96/(.+) /wallpapers/cartoons96/$1 [nc]
RewriteRule ^t101/(.+) /wallpapers/cartoons101/$1 [nc]
RewriteRule ^t120/(.+) /wallpapers/cartoons120/$1 [nc]
RewriteRule ^t128/(.+) /wallpapers/cartoons128/$1 [nc]
RewriteRule ^t160/(.+) /wallpapers/cartoons160/$1 [nc]
RewriteRule ^t174/(.+) /wallpapers/cartoons174/$1 [nc]
RewriteRule ^t176/(.+) /wallpapers/cartoons176/$1 [nc]
RewriteRule ^t240/(.+) /wallpapers/cartoons240/$1 [nc]
#this test works works
RewriteRule ^test/(.+)/(.+) /test.php?id=$1&nm=$2 [nc]
#this is the problem area
RewriteRule ^wallpaper/(.+)/(.+)/(.+) /wallpaper.php?id=$1&cat=$2&size=$3 [nc]
#stop showing .inc contents
<Files *.inc>
order allow,deny
deny from all
</Files>
# move old pages
Redirect 301 /cars128.php http://www.free-mobile.net/wallpaper.php?cat=cars&size=128
Redirect 301 /misc128.php http://www.free-mobile.net/wallpaper.php?cat=misc&size=128
Redirect 301 /cartoons128.php http://www.free-mobile.net/wallpaper.php?cat=cartoons&size=128
the test url:
http://www.free-mobile.net/test/one/two

and code:
Code:
<html>
<head>
<title>Test Page</title>
</head>
<body>
ID: <strong><?php echo $_GET['id'] ?></strong> <br />
NM: <strong><?php echo $_GET['nm'] ?></strong> <br />
</body>
</html>
this doesn't work for example:
http://www.free-mobile.net/wallpaper/1/cars/128

php doesn't see the variables in the url and reverts to the defaults I put in

source for that is really long and in two main parts so ive put it in a txt files here (wallpaper.php): http://www.free-mobile.net/external/cthwallpaper.txt
and here (gallery/main.php): http://www.free-mobile.net/external/cthmain.txt


Phew!
Thanks in advance!
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #2  
Old July 17th, 2006, 02:32 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
The rule seems fine. It is your links that you haven't coded correctly.

You need to change them to suite the rule.

e.g.
Code:
<img src="wallpapers/misc128/bm_greensmear.jpg" class="link1" alt="misc wallpaper 0" title="free misc wallpaper 0"/>
Will be output as
Code:
http://www.free-mobile.net/wallpaper/1/cars/128/wallpapers/misc128/bm_greensmear.jpg
Which doesn't exist.

What you want is a link to
Code:
http://www.free-mobile.net/wallpapers/misc128/bm_greensmear.jpg
You can do this by setting the path from the webroot

Code:
<img src="/wallpapers/misc128/bm_greensmear.jpg" class="link1" alt="misc wallpaper 0" title="free misc wallpaper 0"/>
Or by using an absolute URL using PHP Server Variables to get the script name.


Do that same for your links.

Code:
<a href="window.php?id=0&amp;cat=misc&amp;size=128">
are in the wrong format. You need to change them to your rewritten URL
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #3  
Old July 17th, 2006, 04:54 PM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
thanks

yeah I know i'd have to change the links

but right now going directly to this url:
http://www.free-mobile.net/wallpaper/1/cars/128

doesn't work as the GET command doesn't seem to work and instead it's using the rule I put in to make the default page 1, misc catigory and size 128
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #4  
Old July 17th, 2006, 07:38 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
As far as I can see it is working. It is bringing up the same page as
http://www.free-mobile.net/wallpaper...=cars&size=128

But because your links are wrong the CSS or images are not being loaded.
Code:
<link rel="stylesheet" href="css/site.css" />
Means that it is linking to
Code:
http://www.free-mobile.net/wallpaper/1/cars/128/css/site.css
This does not exist.


What you want is
Code:
<link rel="stylesheet" href="/css/site.css" />

Sp that the link is
Code:
http://www.free-mobile.net/css/site.css
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #5  
Old July 17th, 2006, 07:47 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
Just noticed that the content is not exact. Fix the links first so we have a proper comparison.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #6  
Old July 17th, 2006, 08:06 PM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
Quote:
Originally Posted by degsy
Just noticed that the content is not exact. Fix the links first so we have a proper comparison.
not sure what you mean by that...

fixed the link to the css so the page is styled, although that wouldn't be an issue if the rewrite and php was working ala the test i did
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #7  
Old July 17th, 2006, 08:56 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
You still haven't changed your URLs.

e.g. You are trying to show an image
Code:
<img src="wallpapers/misc128/bm_greensmear.jpg"
When it is loaded the source will be
Code:
http://www.free-mobile.net/wallpaper/1/cars/wallpapers/misc128/bm_greensmear.jpg
This URL does not exist.

The source should be
Code:
<img src="/wallpapers/misc128/bm_greensmear.jpg"

You need to do the same with your hyperlinks. You need to replace your PHP code to point to the rewrite URL instead of the querystring.

Code:
echo ("<a href=\"".$me."?id=".$fc."&amp;cat=".$cat."&amp;size=".$size."\">".$fc."&nbsp;</a>  ");
You need that changed so it will output
http://www.free-mobile.net/wallpaper/1/cars/128
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #8  
Old July 17th, 2006, 09:01 PM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
yes I realise that, however although the images will be dead links it should at least load up the cars page and not misc (the default) when you go to the example url above...
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #9  
Old July 17th, 2006, 09:10 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
I know that is not your major problem, but it would be easier to see what is wrong if we can see the page how it should be, even though it is not grabbing the correct vars.


Have you tried removing your validation code. It seems that if you request a wrong URL it defaults to misc. Try removing that code to see what errors are output.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #10  
Old July 17th, 2006, 09:22 PM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
ok ive tried removing the validation for cat and page as well as the check to make sure the cat is allowed (stops some hacks) and get:

Warning: opendir(wallpapers/128/): failed to open dir: No such file or directory in /home/www/freenmob/gallery/main.php on line 17

1/0 (Number of wallpapers 0) Next Page

Pages:

Warning: Invalid argument supplied for foreach() in /home/www/freenmob/gallery/main.php on line 56


im assuming thats because php finds nothing in the vars so can't open a blank folder...


I can't really adjust the links because the script is live on my site and doing so will break things which work just now (with the long urls)




I then tried not using the include and putting the whole thing into the wallpaper.php file:

Code:
<?php 
require("gallery/cats_config.inc"); // includes config file
require("layout/top.txt"); 
$cat = $_GET['cat']; //gets category of wallpaper
$size = $_GET['size']; //gets size of wallpaper
if (!isset($_GET['cat'])) {  //what to do if there is no cat
			$cat = "misc"; 
		}
if (!isset($_GET['size'])) {  //what to do if there is no size
			$size = "128"; 
		}
$h1name = $h1names[$cat];
$h1size = $h1sizes[$size];

?>

<meta name="keywords" content="<?php echo($h1name.", ".$h1size); ?>, free, mobile, wallpaper, wallpapers, wap" />
<meta name="description" content="Free <?php echo($h1name." ".$h1size); ?> colour wallpapers for mobile phones." />
<meta name="robots"content="index,follow" />
<meta name="copyright" content="Copyright 2004-2006 free-mobile.net. All Rights Reserved." />
<title><?php echo($h1name." ".$h1size); ?> @  <?php include("layout/title.txt"); ?> </title>
<?php include("layout/masthead.txt");
include("layout/sidebar.txt"); 
//protection for cat and size
if (in_array($cat, $pass) && in_array($size, $pass_size)) {
?>
<h1><?php echo($h1name." ".$h1size); ?></h1>
<?php
//include ("gallery/main.php"); 









/*All this is Copyright 2006 Colin Symon (for free-mobile.net)
You may use/modify it but you MUST leave a clearly visible link back to free-mobile.net on any pages this script
is used on. */
//version 0.3 13/06/06
$realname = $_GET['id']; //gets visible id
if (!isset($_GET['id'])) {  //what to do if there is no id
			$realname = 1; 
		}
require("gallery/gallery_config.inc"); // includes config file
require("gallery/cats_config.inc"); // includes config file
require("gallery/ad_config.inc"); //gets ad for mid gallery
$name = $realname*$notopage; //works out hidden name for images on page
$filecount = 0; //sets file counter

//this opens the folder and reads in the images. Counts the total number as well.
if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && (substr(strtolower($file),-3) == 'jpg')) {
           $files[] = $file;
           if ($sort == "decending"){
           rsort($files);
           }
           $filecount++;
       }
   }
   closedir($handle);
}
$rawpage = $filecount/$notopage; //how many pages not rounded
$pages = round($rawpage+0.5); // how many pages rounded up
if ($rawpage == $pages-1){ //0.2 smart fix for rounding up bug if raw pages is a whole number
$pages = $rawpage;
}
echo ("<p>");
if ($realname != 1){
  echo ("<span style=\"font-weight:bold;\"><a href=\"".$me."?id=".($realname-1)."&amp;cat=".$cat."&amp;size=".$size."\">Previous Page </a></span>");
}
echo ("&nbsp;&nbsp;&nbsp;".$realname."/" .$pages);
echo ("&nbsp;&nbsp;&nbsp;(Number of wallpapers " .$filecount. ")&nbsp;&nbsp;&nbsp;");
if ($realname != $pages){
  echo ("<span style=\"font-weight:bold;\"><a href=\"".$me."?id=".($realname+1)."&amp;cat=".$cat."&amp;size=".$size."\">Next Page</a></span>");
}
echo ("</p><p><span style=\"font-weight:bold;\">Pages: ");
$fc = 1;
while ($fc <= $pages) {
  echo ("<a href=\"".$me."?id=".$fc."&amp;cat=".$cat."&amp;size=".$size."\">".$fc."&nbsp;</a>  ");
  $fc++;
}
echo ("</span></p>");

$colCtr = 0; //gets the trs in the right place
$counter = 0;  //which images to appear on this page is based on this value
$rowcount = 0; //gets row number to insert ad
//display the table
echo ("<table class=\"gallery\"><tr class=\"gallery\"><td></td>" . "\n");
foreach($files as $file )
{
if ($counter > ($name-$notopage-1) && $counter < $name){
  if($colCtr %$cols == 0) {
      if ($rowcount == 1){
        echo ("</tr><tr><td colspan=\"". $cols ."\"><div class=\"center\"><div class=\"centered\">".$ad."</div></div></td></tr><tr>"  . "\n");
        $rowcount++;
      }
      else{
    echo ("</tr><tr><td colspan=\"". $cols ."\"></td></tr><tr>"  . "\n");
    $rowcount++;
    }
  }
    echo ("<td class=\"gallery\"><a href=\"window.php?id=" .$counter."&amp;cat=".$cat."&amp;size=".$size."\"><img src=\"" . $images . $file . "\" class=\"link1\" alt=\"".$cat." wallpaper ".$counter."\" title=\"free ".$cat." wallpaper ".$counter."\"/></a> </td>"  . "\n");
  $colCtr++;
  $counter++;
}
else {
$counter++; //have to keep counter running or the page 1 images will always appear
}
}
echo ("</tr></table>");
//end









}
else {
      echo("<h1>Bad Request</h1>Please use the links provided.");
      }
include("layout/rightside.txt"); 
include("layout/footer.txt"); ?>
sadly it does the same thing...
__________________
Free Mobile Phone Wallpapers

Last edited by 30111987; July 17th, 2006 at 09:25 PM.
Reply With Quote
  #11  
Old July 17th, 2006, 09:24 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
Quote:
wallpapers/128/
You are going to have to extract the url into pieces so you have the correct vars for your script.

Look into Split or Explode
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #12  
Old July 18th, 2006, 12:06 AM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
hmm

that is strage tho because it works fine with my test script...
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #13  
Old July 18th, 2006, 11:31 AM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
The only other thing I could suggest is to start from strach on your gallery script to see where it breaks.

Your rewrite rule seems fine.

Back to basics. Have you tried a foreach loop through $_GET to see what vars you are getting?
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #14  
Old July 19th, 2006, 12:51 AM
30111987's Avatar
30111987 30111987 is offline
CTH Subscriber
 
Join Date: Jul 2002
O/S: Windows XP Pro
Location: Scotland
Posts: 1,390
eh...

I have tried a basic echo ($_GET['cat']);
it outputs nothing

im going to setup a test server on my pc and see if it's possibly the web-mania server at fault
__________________
Free Mobile Phone Wallpapers
Reply With Quote
  #15  
Old July 19th, 2006, 11:27 AM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
Put this code after the body tag
PHP Code:
<?php
if(isset($_GET)){
    foreach(
$_GET as $key => $val){
        echo 
"$key: $val<br>";
    }
}
?>
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
Reply

Bookmarks

Topic Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:26 PM.

[ RSS ]