Results 1 to 9 of 9

Thread: mod_rewrite

  1. #1
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mod_rewrite

    how to make URLs look like hxxp://localhost/site/picture.html instead of /site/index.php?p=picture.jpg? tnx.

    here is the code that im working with and i can't seem to figure it out....
    Code:
    <?php $albumName = "some title here"; // Name your album!
    $p = $_GET['p'];
    if ($handle = opendir("images")) {
    	$i = 1;
    	while (false !== ($file = readdir($handle))) {
    		if ($file != "." && $file != "..") {
    			$img[$i] = $file;
    			if ($p == $img[$i]) {
    				$ci = $i;
    			}
    			$i++;
    		}
    	}
    	closedir($handle);
    	$ti = $i - 1;
    	$pi = $ci - 1;
    	if ($p == "") {
    		$ni = $ci + 2;
    	} else {
    		$ni = $ci + 1;
    	}
    	$prevNext = "";
    	if ($pi > 0) {
    		$piFile = $img[$pi];
    		$prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $piFile . "\" title=\"show previous image\"></a>";
    	} else {
    		$prevNext .= "";
    	}
    	$prevNext .= " | ";
    	if ($ni <= $ti) {
    		$niFile = $img[$ni];
    		$prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $niFile . "\" title=\"show next image\"></a>";
    	} else {
    		$prevNext .= "";
    	}
    	if ($p == "") {
    		$p = $img[1];
    	}
    }
    ?> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    	<title><?php echo $albumName; ?></title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	<meta http-equiv="imagetoolbar" content="no">
    </head>
    <body>
    <h1><?php echo $albumName; ?></h1>
    <div class="hRule"></div>
    <table border="0" cellpadding="0" cellspacing="0" align="center">
    	<tr align="center">
    		<td class="nextPrevious"><?php echo $prevNext; ?></td>
    	</tr>
    	<tr align="center">
    		<td><img src="images/<?php echo $p; ?>" alt="<?php echo $$albumName; ?>" border="0"></td>
    	</tr>
    </table>
    <p>some other text here</p>
    </body>
    </html>
    tnx.
    Last edited by Snookerman; 11-17-2009 at 08:16 AM.
    Please don't mind me. I am just posting a lot of nonsense.

  2. #2
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^.*\.
    RewriteRule ^(.*)$ index.php?p=$1

  3. #3
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    You should have Apache webserver and mode_rewrite must be enabled for this to work.

    Create a file named .htaccess in the folder /site/

    edit .htaccess and update the contents:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)\.html$ index.php?p=$1.jpg [NC]
    RewriteRule ^$ index.php [NC]

  4. #4
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)\.html$ index.php?p=$1.(gif|jpg|png|bmp)$ [NC]
    RewriteRule ^$ index.php [NC]
    will something this work also? notice the highlight.

    thnx.
    Please don't mind me. I am just posting a lot of nonsense.

  5. #5
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by prasanthmj View Post
    You should have Apache webserver and mode_rewrite must be enabled for this to work.

    Create a file named .htaccess in the folder /site/

    edit .htaccess and update the contents:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)\.html$ index.php?p=$1.jpg [NC]
    RewriteRule ^$ index.php [NC]
    tried that. still didn't get the desired result. tnx though.
    Please don't mind me. I am just posting a lot of nonsense.

  6. #6
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how to put "RESOLVED" in my thread?
    Please don't mind me. I am just posting a lot of nonsense.

  7. #7
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You can go to your first post in the thread, click then click Go Advanced and add the Resolved prefix to the thread title.

    Happy foruming!

  8. #8
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    looked into that. didn't see any EDIT button to click. ^_^
    Please don't mind me. I am just posting a lot of nonsense.

  9. #9
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    For some reason it disappears after some time.. vBulletin..
    I'll do it for you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •