Problem with Shortening URLS, Spent two days so far. htacess +php script

Discussion in 'Apache' started by mynyhart, Sep 15, 2010.

  1. #1
    http://www.myspace-help.com/Myspace-Backgrounds/1.htm
    is the Final Product of what i was able to do with my script + .htaccess
    Its a combanation of

    htacess
    
    RewriteRule ^(.*)/(.*).htm$ $1/index.php?page=$2  [L]   
    
    Code (markup):
    php script
    
    <?php
    require_once( dirname(__FILE__) . '/_config.php');
    if(!isset($_GET['page'])):
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: 1.htm");
    exit();
    endif;
    $page = preg_replace("@[^0-9]@", "", $_GET['page']);
    }
    PHP:
    How do i properly turn what is normally http://www.myspace-help.com/Myspace-backgrounds/?=page1
    to http://www.myspace-help.com/Myspace-Backgrounds1.htm


    This is the whole code section of the script if it helps.
    <?php
    require_once( dirname(__FILE__) . '/_config.php');
    
    if(!isset($_GET['page'])):
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: 1.htm");
    exit();
    endif;
    $page = preg_replace("@[^0-9]@", "", $_GET['page']);
    
    $_dir = end(explode('/', $start));
    
    $_cache = 'categories';
    
    if($_caching_on == 1){
    require_once( dirname(__FILE__) . '/_encoded/cache_head.php');
    }
    
    else{
    require_once( $_path . '/_inc/_encoded/'.$_cache.'.php');
    
    if( $page > $pages ):
    
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: 1.htm");
    exit();
    
    endif;
    }
    
    $_rep = array('-'=>' ','_'=>' ','1'=>'','2'=>'','3'=>'','4'=>'','5'=>'','6'=>'','7'=>'','8'=>'','9'=>'');
    
    
    $tags = ucwords(trim(strtr(current($SliceArr), $_rep))).', ';
     
    $total = (count($SliceArr)-1);
    
    for($i=0; $i<$total; $i++){
    
    if($i != ($total - 1)){
    $tags .= ucwords(trim(strtr(next($SliceArr), $_rep))).', ';
    }else{
    $tags .= ucwords(trim(strtr(next($SliceArr), $_rep)));
    	}
    }
    
    include( $_path . '/_theme/header.php');
    echo '<h1>'.$_dir.' Category </h1>'."\n";
    echo '<div id="play">'."\n";
    if(file_exists('before.php')) include('before.php');
    
    foreach($SliceArr  as $OBJ):
    
    $name = ucwords(trim(strtr($OBJ, $_rep)));
    
    if(file_exists($_path.'/'.$_dir.'/'.$OBJ.'/thumb.jpg')){
    $THUMB = 'thumb.jpg';
    }
    
    elseif(file_exists($_path.'/'.$_dir.'/'.$OBJ.'/thumb.png')){
    $THUMB = 'thumb.png';
    }
    
    elseif(file_exists($_path.'/'.$_dir.'/'.$OBJ.'/thumb.gif')){
    $THUMB = 'thumb.gif';
    }
    
    echo 
    
    '<div id="cata" class="'.$_dir.'_category">'."\n".
    '<p class="'.$_dir.'_category_title"><h2>'.$name.'</h2></p>'."\n".
    '<a href="'.$_url.'/'.$_dir.'/'.$OBJ.'/"><img src="'.$_url.'/'.$_dir.'/'.$OBJ.'/'.$THUMB.'" border="0" class="nude"/></a>'."\n".
    '</div>'."\n";
    
    endforeach;
    
    $num = 1;
    
    echo
    '</div>'."\n".
    '<div id="pnav">'."\n".
    '<span id="pages">Pages:</span>&nbsp;'."\n";
    
    
    while( $num <=  $pages ):
    
    if($page != $num)
    echo '<a href="'.$num.'.htm" class="pnum">'.$num.'</a>'."\n";
    
    elseif($page == $num)
    echo $num."\n";
    
    $num++;
    
    endwhile;
    echo '</div>'."\n";
    
    if(file_exists('after.php')) include('after.php');
    
    include( $_path . '/_theme/footer.php');
    
    if($_caching_on == 1){
    require_once( dirname(__FILE__) . '/_encoded/cache_foot.php');
    }
    
    ?>
    
    PHP:

    And my current htacess
    Options -Indexes
    Options +FollowSymLinks
    DirectoryIndex index.php
    RewriteEngine on
    RewriteRule ^(.*)/(.*).htm$ $1/index.php?page=$2  [L] 
    RewriteRule ^(.*)/(.*)/(.*).htm$ $1/2$/index.php?page=$3  [L] 
    ErrorDocument 404 /404.php
    <ifModule mod_php5.c>
     php_value default_charset utf-8
    </ifModule>
    Code (markup):
    Ill be on the forums all day reading up on it and checking out new stuff but if you want to msg me on msn it is Calm.to.catastrophe@gmail.com
     
    mynyhart, Sep 15, 2010 IP
  2. mynyhart

    mynyhart Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok So i got them all shortened but this is the whole problem i have so far.

    Michael says: (2:48:22 PM)
    RewriteRule ^(.*)/(.*).htm$ $1/index.php?page=$2 [L]
    RewriteRule ^(.*)/(.*)/(.*).htm$ $1/2$/index.php?page=$3[L]
    RewriteRule ^(.*)-(.*)-(.*).htm$ $1/$2/$3.htm [L] [NC]
    RewriteRule ^(.*)_(.*).htm$ $1/$2.htm [L]
    RewriteRule ^(.*)-(.*)-(.*).gif$ $1/view.php?cat=$2&layout=$3.gif [L] [NC]
    RewriteRule ^(.*)-(.*)-(.*).jpg$ $1/view.php?cat=$2&layout=$3.jpg [L] [NC]
    RewriteRule ^(.*)-(.*)-(.*).png$ 
    This rewrite creates these pages
    http://www.myspace-help.com/Myspace-Backgrounds_1.htm
    http://www.myspace-help.com/Myspace-Backgrounds-Animated_Backgrounds-1.htm
    http://www.myspace-help.com/Myspace-Backgrounds-Animated_Backgrounds-animal_13.gif


    What i want is

    http://www.myspace-help.com/Myspace-Backgrounds/?page=1
    to
    http://www.myspace-help.com/Myspace-Backgrounds-1.htm

    http://www.myspace-help.com/Myspace-Backgrounds/Abstract-Backgrounds/?page=1 to
    http://www.myspace-help.com/Abstract-Backgrounds-1.htm

    http://www.myspace-help.com/Myspace-Backgrounds/Abstract-Backgrounds/view.php?cat=Abstract-Backgrounds&layout=Abstract-1.jpg
    to
    http://www.myspace-help.com/Abstract-Backgrounds-Abstract-1.htm

    Ive collabed with my server owner and other forums and read for days and tested everything and i keep messing it up and getting 500's or not the result im looking for
     
    mynyhart, Sep 19, 2010 IP
  3. mynyhart

    mynyhart Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I Had to start from scratch again because the code i wrote only worked for one catagory and the php script i was useing did not like it

    
    # Rewrites My main Catagories - Example myspace-help.com/Myspace-Backgrounds to Myspace-Backgrounds_1.htm
    # And Myspace-help.com/Myspace-Comments/ to Myspace-Comments_1.htm
    RewriteRule ^([a-zA-Z-_]+)/(\d+)\.htm$ $1/?page=$2 [L,NC] 
    RewriteRule ^([a-zA-Z-_]+)_(\d+)\.htm$ $1/$2.htm [L,NC] 
    
    Code (markup):
    This one works perfect. it turns all of my main catagories into what it needs to be

    Now inside Myspace-Backgrounds_1.htm there is mutli catagories such as Animated Backgrounds and Yellow Backgrounds and myspace-comments/ Has things like Heart , Love, OMG, ZOMG

    How do i turn these sub catagories dynamicly or even something where i have to copy the mod rewrite for each catagory like so

    myspace-help.com/Yellow-Backgrounds-1.htm

    The Old code i used was

    
    RewriteRule ^([a-zA-Z-_]+)-(\d+)\.htm$ Myspace-Backgrounds/$1-$2.htm [L,NC]
    
    Code (markup):
    But when i tried
    RewriteRule ^([a-zA-Z-_]+)-(\d+)\.htm$ Myspace-Comments/$1-$2.htm [L,NC]
    Everything broke The myspace backgrounds still worked but the Myspace Comments categories did not.

    And Finally after this problem is solved i still have my View.php Problem

    I Used this code
    
    # View.php Rewrite
    RewriteRule ^([a-zA-Z-_]+)-([A-Za-z0-9-_]+).(gif|jpg|swf|flv|png)$ Myspace-Backgrounds/view.php?cat=$1&layout=$2.$3 [L,NC]
    
    Code (markup):
    Which had the same effect as My Myspace-Backgrounds probleem

    I tried
    RewriteRule ^([a-zA-Z-_]+)-([A-Za-z0-9-_]+).(gif|jpg|swf|flv|png)$ Myspace-Comments/view.php?cat=$1&layout=$2.$3 [L,NC]

    and The backgrounds one still worked but the one for Myspace-Comments did not.

    And again here is all of my original Stings
    *This one seems to be working correctly*
    
    http://www.myspace-help.com/Myspace-Backgrounds/?page=1 
    http://www.myspace-help.com/Myspace-Comments/?page=1 
    To 
    http://www.myspace-help.com/Myspace-Backgrounds_1.htm 
    http://www.myspace-help.com/Myspace-Comments_1.htm
    
    Code (markup):

    Next this is what needs to be solved as ive tried everything and still no luck
    
    http://www.myspace-help.com/Myspace-Backgrounds/Abstract_Backgrounds/?page=1
    http://www.myspace-help.com/Myspace-Comments/Spring/?page=1
    
    To Something like
    http://www.myspace-help.com/Myspace-Backgrounds-Abstract_Backgrounds-1.htm
    http://www.myspace-help.com/Myspace-Comments-Spring-1.htm
    
    or even better which is how i wanted it the first time
    http://www.myspace-help.com/Abstract_Backgrounds-1.htm
    http://www.myspace-help.com/Spring-1.htm
    
    Code (markup):
    And then my View.php Sting

    
    http://www.myspace-help.com/Myspace-Backgrounds/view.php?cat=Animated-Backgrounds&layout=animated_7.gif
    http://www.myspace-help.com/Myspace-Comments/view.php?cat=Autos&layout=auto1.gif
    
    To Anything like
    
    http://www.myspace-help.com/Animated-Backgrounds-animated_7.gif
    http://www.myspace-help.com/Autos-auto1.gif
    
    Code (markup):
    Any Help Would be Appricated
    If you really want to help Please msg me on msn or Aim
    Sherman Destroy

    I Would be forever Greatful
     
    mynyhart, Sep 22, 2010 IP