AdRock Posted August 19, 2006 Share Posted August 19, 2006 I am trying to do mod rewrite for my website to make the urls user and search engine firendly and am having trouble getting it to work. This is what I've got and it doesn't work.[code]RewriteEngine onOptions +FollowSymlinksRewriteBase /RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]RewriteCond %{HTTP_USER_AGENT} ^ExtractorProRewriteRule ^\.htaccess$ - [F]RewriteRule ^(.*)/(.*)$ $1index?$2[/code]here is the some of the links I would like to usehttp://www.jackgodfrey.org.uk/index.phphttp://www.jackgodfrey.org.uk/index.php?page=contacthttp://www.jackgodfrey.org.uk/index.php?page=news&limit=1&pagenum=4How would i include these links in the .htaccess file? ;D Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/ Share on other sites More sharing options...
onlyican Posted August 20, 2006 Share Posted August 20, 2006 okTry this in your HTACCECSSRewriteEngine OnOptions +FollowSymlinksRewriteRule ^index/([A-Za-z_0-9]*) index.php?page=$1 [L]Then on your website link to them as follows<a href='index/contact'>Contact</a> Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-77525 Share on other sites More sharing options...
AdRock Posted August 20, 2006 Author Share Posted August 20, 2006 Thanks...that worksIs there a way i can change the index to something else so it reads something/contact etcAlso who do I rewrite this urlhttp://www.jackgodfrey.org.uk/index.php?page=news&limit=1&pagenum=4Many thanks for your helpI have found something strange and I don't think it's supposed to be happening.If I click on the contact link multiple times even if I one from a different link i get this url/index/index/index/contact and it doesn't display properly Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-77552 Share on other sites More sharing options...
onlyican Posted August 20, 2006 Share Posted August 20, 2006 yesRewrite Rule LinkyouWant, ActualLink [L]using the ([A-Za-z_0-9]*) it checks for something that is Capital Letters, small letters and numbers only Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-77673 Share on other sites More sharing options...
AdRock Posted August 21, 2006 Author Share Posted August 21, 2006 I have got everything else working but this strange thing happening each time i click a link/index/index/index/index/index/contact Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-77798 Share on other sites More sharing options...
onlyican Posted August 21, 2006 Share Posted August 21, 2006 are you linking<a href='/index/contact'>Contact</a>or<a href='index/contact'>Contact</a>The top one is correct Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-77799 Share on other sites More sharing options...
AdRock Posted August 21, 2006 Author Share Posted August 21, 2006 Can you please tell me if I have got this right[code]RewriteEngine onOptions +FollowSymlinksRewriteBase /RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]RewriteCond %{HTTP_USER_AGENT} ^ExtractorProRewriteRule ^\.htaccess$ - [F]RewriteRule ^index/([A-Za-z_0-9]*) index.php?page=$1[b]RewriteRule ^index/([A-Za-z_0-9]*)/([A-Za-z_0-9]*)/([A-Za-z_0-9]*) index.php?page=$1&limit=$2[/b]$pagenum=$3 [L][/code]and how do i rewrite these urls for mod rewrite? It for the last line of code where I would get [b]index.php?page=new&limit=1&pagenum=4[/b]index.php?page=news&limit=$limit&pagenum=$prev_pageindex.php?page=news&limit=$limit&pagenum=$aThis is in my pagination script I downloaded and the strings in there are set variables Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-78012 Share on other sites More sharing options...
onlyican Posted August 21, 2006 Share Posted August 21, 2006 All you need isRewriteEngine onOptions +FollowSymlinksRewrireRule ^index/([a-z]*)/([0-9]*)/([0-9*) index.php?page=$1i&new=$2$pagenum=$3 [L](remember the flag at the end [L]) Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-78027 Share on other sites More sharing options...
AdRock Posted August 22, 2006 Author Share Posted August 22, 2006 That makes sense now but how do i change the actual urls in the page themselves? I have it all working so the mod rewrite works but for the second rewrite rule. I can't tell if it works becuase of the links on the page<a href=index.php?page=news&limit=$limit&pagenum=$prev_page>Prev.</a><a href=index.php?page=news&limit=$limit&pagenum=$a> $a </a><a href=index.php?page=news&limit=$limit&pagenum=$next_page><b>Next</b></a>Here is my script so you can see how it works[code]<? //REMEMBER TO CONNECT TO DATABASE! include_once("includes/connection.php"); @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); //**EDIT TO YOUR TABLE NAME, ECT. $t = mysql_query("SELECT * FROM `news`"); if(!$t) die(mysql_error()); $a = mysql_fetch_object($t); $total_items = mysql_num_rows($t); $limit = $_GET['limit']; $type = $_GET['type']; $page = $_GET['pagenum']; //set default if: $limit is empty, non numerical, less than 1, greater than 50 if((!$limit) || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) { $limit = 1; //default } //set default if: $page is empty, non numerical, less than zero, greater than total available if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { $page = 1; //default } //calcuate total pages $total_pages = ceil($total_items / $limit); $set_limit = $page * $limit - ($limit); //query: **EDIT TO YOUR TABLE NAME, ECT. $q = mysql_query("SELECT id,title,content, DATE_FORMAT(time, '%W %D %M %Y') as date, photo FROM news ORDER BY time DESC LIMIT $set_limit, $limit"); if(!$q) die(mysql_error()); $err = mysql_num_rows($q); if($err == 0) die("No matches met your criteria."); $numofrows = mysql_num_rows($q);//Results per page: **EDIT LINK PATH** echo(" <a href=?page=news&limit=10&pagenum=1></a> <a href=?page=news&limit=25&pagenum=1></a> <a href=?page=news&limit=50&pagenum=1></a>"); //show data matching query: while($code = mysql_fetch_array($q)) { echo "<div id=\"right\"><h3>".$code['title']."</h3><i>Date added: ".$code['date']."</i><p class=\"style3\"><img src=images/".$code['photo']." align=\"right\" class=\"right\">".nl2br($code['content'])."</p></div>\n";} $id = urlencode($id); //makes browser friendly //prev. page: **EDIT LINK PATH** $prev_page = $page - 1; if($prev_page >= 1) { echo("<b><<</b> <a href=?page=news&limit=$limit&pagenum=$prev_page><b>Prev.</b></a>"); } //Display middle pages: **EDIT LINK PATH** for($a = 1; $a <= $total_pages; $a++) { if($a == $page) { echo("<b> $a</b> | "); //no link } else { echo(" <a href=?page=news&limit=$limit&pagenum=$a> $a </a> | "); } } //next page: **EDIT THIS LINK PATH** $next_page = $page + 1; if($next_page <= $total_pages) { echo("<a href=?page=news&limit=$limit&pagenum=$next_page><b>Next</b></a> > >"); } //all done ?>[/code]Here is my updated .htaccess mod rewrite[code]Options +FollowSymLinksRewriteEngine onRewriteBase /RewriteRule ^honeylands/(.*) index.php?page=$1 [NC]RewriteRule ^honeylands/(.*)/(.*)/(.*) index.php?page=$1&limit=$2&pagenum=$3 [L][/code]Is this right for the internal urls? It seems to display correctly in the browser address bar but it defualts back to the home page which is now /honeylands/index<a href=/honeylands/news/$limit/$prev_page><b>Prev.</a><a href=/honeylands/news/$limit/$next_page><b>Next</a><a href=/honeylands/news/$limit/$a> $a </a> Quote Link to comment https://forums.phpfreaks.com/topic/18063-how-the-hell-do-i-do-mod-rewrite-resolved/#findComment-78554 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.