realcoder Posted July 18, 2010 Share Posted July 18, 2010 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 thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/ Share on other sites More sharing options...
dreamwest Posted July 18, 2010 Share Posted July 18, 2010 RewriteRule ^songs/movie/(.*).html songs.php?movie=$1 [L,QSA] Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087729 Share on other sites More sharing options...
ndee Posted July 18, 2010 Share Posted July 18, 2010 .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. Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087730 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087740 Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087750 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 sorrry working but wanna ask now how i change alll link to songs/movie/moviename.html becoz how is it possible ? mean menually after putting i get this page but now how i change alll link becoz that are atuomatically generating Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087764 Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 but now how i change alll link becoz that are atuomatically generating You'll have to modify your code. Are you using a third party script or your own? Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087765 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087766 Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087767 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 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: Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087848 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087849 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 this is the main movies.php code where i have to make changing what i do :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>"; Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087853 Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 Change <a href='songs.php?movie=".$get['name']."'> to <a href='/proj/songs/movie/{$get['name']}.html'> That will change your urls to yourdomain.com/proj/movie/Moviename.html Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087855 Share on other sites More sharing options...
realcoder Posted July 18, 2010 Author Share Posted July 18, 2010 thanks bro can u tell me from where i can learn this for my feature use <a href='/proj/movie/{$get['name']}.html'> mean u write this url i don't get the point of {} did i use {} these brackets where i have to use variables ?? Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1087883 Share on other sites More sharing options...
cags Posted July 19, 2010 Share Posted July 19, 2010 Curly braces are a method to delimit variables within strings. It allows you to do things such as access array keys using single quotes within the string. Place variables with letters directly either side of them, etc. This is fairly basic PHP syntax. http://www.php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1088063 Share on other sites More sharing options...
realcoder Posted July 19, 2010 Author Share Posted July 19, 2010 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 what is this all matter any little guaidence or explanation about this Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1088306 Share on other sites More sharing options...
realcoder Posted July 19, 2010 Author Share Posted July 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1088332 Share on other sites More sharing options...
wildteen88 Posted July 19, 2010 Share Posted July 19, 2010 ^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. Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1088356 Share on other sites More sharing options...
realcoder Posted July 20, 2010 Author Share Posted July 20, 2010 thanks bro Quote Link to comment https://forums.phpfreaks.com/topic/208088-how-to-rewrite/#findComment-1088619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.