Jump to content

how to rewrite


realcoder

Recommended Posts

i want to rewrite url of my script Seo friendly

please little guide me

which rules i use

& how

for example this is the eactual url of my script

 

http://localhost/proj/songs.php?movie=Kajrare

i want to rewrite every url which is songs.php?movie=moviename

look like

songs/movie/moviename.html

or only look like localhost/proj/movie/moviename.html

i know we can do this

but i am very new so don't know the exact rule :confused:

thanks in advance

Link to comment
Share on other sites

.htaccess is the answer.

 

Add this to your .htaccess file usually found in your local web folder.

 

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^movie/(.*)/$ songs.php?movie=$1

 

It... should work.

 

Good luck,

Andy.

Link to comment
Share on other sites

RewriteEngine On
RewriteRule ^songs/movie/(.*).html  songs.php?movie=$1 [L,QSA]

 

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^movie/(.*)/$ songs.php?movie=$1

i have try both codes but nohting changing :(

even after putting .htaccess on main & also after copying that in proj folder where my all proj files are

Link to comment
Share on other sites

i have try both codes but nohting changing

Do not be under the impression that mod_rewrite will change your links for you. You'll have to edit your links manually.

 

even after putting .htaccess on main & also after copying that in proj folder where my all proj files are

You should be placing the .htaccess file in your proj/ directory with the following code

RewriteEngine On
RewriteRule ^songs/movie/(.*).html  songs.php?movie=$1 [L,QSA]

Now go to http://localhost/proj/songs/movie/Kajrare.html and it will call songs.php?move=Kajrare

Link to comment
Share on other sites

i am using my own

but in script if i change in script how that will fetch data

for example

i m using songs.php?movie=movie

here i am passing movie name thorugh get method

then i run query

select * from movies where moviename=moviename

 

if i change in how i pass veriable ?

& how i can change manually link of every movie that's not little

well that's on like

not big script

uu can check bro

& give me idea

http://www.hostrox.com/proj

Link to comment
Share on other sites

am using my own

but in script if i change in script how that will fetch data

for example

i m using songs.php?movie=movie

here i am passing movie name thorugh get method

then i run query

select * from movies where moviename=moviename

 

if i change in how i pass veriable ?

You wouldn't change that part of the code. You only need to change the format of your links, ie rather than having your links as

<a href="songs.php?movename=moveiname">Moviename</a>

You'll change them to

<a href="songs/movie/moveiname.html">Moviename</a>

 

If you post the part of the your code that generates your links I'll suggest what you need to change.

Link to comment
Share on other sites

here is the movie.php code in which m generating automatically new added movie link as u can see at

http://localhost/proj/movies.php?id=1

 

thorugh while loop

 

this is code

 

<?php
session_start();
include "inc.php";
$id = $_GET['id'];


$page_name = $_SERVER['PHP_SELF'];
$start = $_GET['start'];
if(!isset($start)){
    $start = 0;
}
$limit = 30;
$back = $start - $limit;
$next = $start + $limit;



$noOfCols=5;
$que1 = "SELECT * FROM movies where catid='$id'";
$exe2 = mysql_query($que1);
$count = mysql_num_rows($exe2);
?>
<html>
<head><title>Movies....</title>
<link rel="stylesheet" type="text/css" href="proj.css" />
</head>
<body>
<table width="900" border="1" align="center">
<tr><td height="100%" align="left" valign="top" colspan="3"><?php include "head.php"; ?></td></tr>
<tr><td width="150" align="left" valign="top">
<?php include "catg.php"; ?>
</td><td>
<table align="center">
<?php
$que = "SELECT * FROM movies where catid='$id' limit $start,$limit";

$exe = mysql_query($que);
while($get = mysql_fetch_array($exe))
{
    if($i==0)
        echo '<tr>';

    echo "<td height='150' align='left' valign='top'><a href='songs.php?movie=".$get['name']."'>".$get['name']."<br/><img width='100' height='130' border='0' src='".$get['picture']."' /></a></td>";

    $i++;
    if($i==$noOfCols)
    {
        echo '</tr>';
        $i=0;
    }
}


?>
</table>
<?php
echo "<table align='center'><tr><td align='center'>";
if($back >= 0){
    echo "<a href='$page_name?id=$id&start=$back'>Prev</a> ";
}
$j = 1;
for($i=0; $i < $count ; $i = $i + $limit){
if($i <> $start){
    echo "<a href='$page_name?id=$id&start=$i'>$j</a> ";
}
else{
    echo $j;
}
$j++;
}
if($next < $count){
    echo"<a href='$page_name?id=$id&start=$next'>NeXt</a> ";
    }
    echo "</td></tr></table>";



?>
</td>
<td width="150" align="left" valign="top"><?php include "right.php" ?></td>
</tr>
<tr>
<td colspan="3" align="center" valign="top"><?php include "footer.php" ?></td>
</tr>
</table>
</body>
</html>

 

how i write that it also automatically fetch new addedd movie & show that link like

http://www.hostrox.com/proj/movie/Moviename.html

:confused: :confused:

Link to comment
Share on other sites

this is songs.php code

i also need to change some code in this in the td of play & add in

 

<?php session_start();
include "inc.php";
$id = $_GET['movie'];
$que2 = "SELECT * FROM songs where mname='$id'";
$exe2 = mysql_query($que2);
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="proj.css"/>
<meta name="description" content="<?php echo $id." movie songs";  ?>,Latest movie songs ,hindi movie songs,bolywood movie songs,<?php echo $id." mp3 songs";  ?>,listen online <?php echo $id;?> movie songs" />
<meta name="keywords" content="<?php while($get2 = mysql_fetch_array($exe2)){ echo $get2['tag'].",";}?>" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title><?php echo $id; ?> movie songs</title></head>
<body>
<table width="900" border="1" align="center">
<tr><td height="100%" align="left" valign="top" colspan="3"><?php include "head.php"; ?></td></tr>
<tr><td  width="150" align="left" valign="top">
<?php include "catg.php"; ?>
</td>
<td height="400" align="left" valign="top">
<?php
$folder ="proj"; //Your Script direcotry define here

$songdir = "songs"; //define here the exact same directory which u mention in addtrack.php



$que = "Select * from songs where mname='$id'";



$exe = mysql_query($que);

$cont = mysql_num_rows($exe);
if($cont == 0)
echo "No Song is added";

echo "<table align='center'>

    <tr><td align='center' colspan='5'><h3>$id Movie</h3></td></tr><tr>

        <th width='250'>Name</th>

        <th width='100'>size </th>

        <th width='100'>Download</th>

        <th>Play</td>
        <th> Add in</th>

</tr>";



while ($get = mysql_fetch_array($exe))

{



echo"<tr>

        <td align='left'>".$get['name']."</td>

        <td align='center'>".$get['size']."</td>

        <td align='center'><a href='/".$folder."/".$songdir."/".$get['path']."'><img src='dwn.png' height='15' border='0' title='click for download'/></a></td>

        ";

	?>

        <td align="center"><a onclick="opn('play.php?title=<?php echo $get['name']?>&link=http://<?=$_SERVER['SERVER_NAME']?>/<?=$folder?>/<?=$songdir?>/<?=$get['path']?>')"  href='#'<img src="play.gif" border="0" height="15" title="Play" /></a>
<td align="center"><a onclick="opnn('addsong.php?song=<?php echo $get['path']?>&name=<?php echo $get['name']?>')" href='#'><img src="add.gif" border="0"  height="" title="add in playlist" /></a></td>
      <?php   echo "</tr>";

        

        

}



echo "</table>";

?>
<script type="text/javascript">

function opnn (url){

window.open(url,'assd','width=600,height=400')

return false

}

</script>

<script type="text/javascript">

function opn (url){

window.open(url,'assd','width=200,height=50')

return false

}

</script>

<table align="center"><tr><td align="center"><?php include "ad2.php"; ?></td></tr></table>
</td>
</tr>
<tr>
<td colspan="3" align="center" valign="top"><?php include "footer.php" ?></td>
</tr>
</table>
</body>
</html>

Link to comment
Share on other sites

this is the main movies.php code where i have to make changing what i do  :confused: :confused:

 

$que = "SELECT * FROM movies where catid='$id' limit $start,$limit";

$exe = mysql_query($que);
while($get = mysql_fetch_array($exe))
{
    if($i==0)
        echo '<tr>';

    echo "<td height='150' align='left' valign='top'><a href='songs.php?movie=".$get['name']."'>".$get['name']."<br/><img width='100' height='130' border='0' src='".$get['picture']."' /></a></td>";

Link to comment
Share on other sites

well i wanna ask one question

if we writing the main link in  our file like this

<a href='songs/movie/".$get['name'].".html'>

then why we writing in .htaccess for chanigng link from songs.php?movie=movie to movie/moviename.html

because there is no link like this songs.php?movie=moviname which that change

we changing that manually from our file  :confused:

what is this all matter  :confused:

any little guaidence or explanation about this

Link to comment
Share on other sites

well i got the answer of my last question

can u people explain little to this line

because i wanna learn really exactly for my future use

^movie/(.*).html  songs.php?movie=$1

 

 

as i have download the chat where write srting start with ^

& end with $

but what is $1

why 1 is with $

(.*) and why we wwrite these in brackets

How i know that where i pass variable in string ?

lttle explanation of this string it will be very help for me to understand rewite rule :confused:

Link to comment
Share on other sites

^movie/(.*).html$ is a regular expression.

 

The above expression will match the following url

domain.com/movies/moviename.html

 

(.*) will match any characters in the url, which in your case will be themoviename name. $1 refers back to the matched value. This is what passes the moveiname to PHP.

 

You should have read up on regular expressions and the documentation on mod_rewrite, and a simple mod_rewrite tutorial.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.