paparanch Posted February 3, 2009 Share Posted February 3, 2009 good day everyone! i been looking for a step-by-step tutorial regarding search engine friendly url using htaccess, hope someone could help me here. BTW, im just using xampp and windows XP OS. And i already loaded the mod_rewrite module in the apache. i made a sample php file jut to try to use htaccess for search engine friendly purposes. <------index.php-------> <?php $title = "AKO"; echo "<a href='index.php?title=$title'>"; echo "Book Title"; echo "</a>"; ?> <----End of index.php----> Base on my code above, when i click the "Book Title" the address bar shows "localhost/samp/index.php?title=AKO" So, how can i make it to "localhost/samp/title/AKO"? What code should i put in my .htaccess file to make my url more search engine friendly? Could someone help me with this please? Im getting frustrated with this.. thanx in advanced! Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 3, 2009 Share Posted February 3, 2009 RewriteEngine on RewriteRule ^title/([^/\.]+)/?$ index.php?title=$1 [L] i think? i am not expert i am still learning this is from http://www.workingwith.me.uk/articles/scripting/mod_rewrite Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 3, 2009 Author Share Posted February 3, 2009 tnx bro, but still doesn't work.. the url is still "localhost/samp/index.php?title=AKO" any help pls? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 3, 2009 Share Posted February 3, 2009 you need to change your code to <?php $title = "AKO"; echo "<a href='localhost/samp/title/$title'>"; echo "Book Title"; echo "</a>"; ?> also try using [ code ] [/ code] (without the spaces will generate code boxes like above Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 wow it works! but the problem is my css doesn't load anymore. whats wrong with this? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 try giving your css a full path like /samp/cssfile.css opposed to cssfile.css Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 its still not working master. would u please give a sample file for this? if u don't mind Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 can u show me the code u are suing to include the css file Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 this is the index.php file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ARCKE</title> <link href="css/index.css" rel="stylesheet" type="text/css" /> <body> *******the navigation****** <div class="nav"> <div class="nav_btn"> <a href="index.php"> Home </a> </div> <div class="nav_btn"> <a href="page/<? echo $rates; ?>"> <div> <? echo $nav; ?> </div> </a> </div> ******end of navigation**** </body> </html> Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 try <link href="/samp/css/index.css" rel="stylesheet" type="text/css" /> Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 this is the index.php file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ARCKE</title> <link href="css/index.css" rel="stylesheet" type="text/css" /> <body> <?php $disp_page = $_GET['page']; $pagenum = 2; ?> *******the navigation****** <div class="nav"> <div class="nav_btn"> <a href="index.php"> Home </a> </div> <div class="nav_btn"> <a href="page/<? echo $pagenum; ?>"> Rates </a> </div> </div> ******end of navigation**** *****start of body content**** <?php if($disp_page==2){ include 'rates.php'; } else{ ?> <div class='content_body'> Dynamic Content Here </div> <? } ?> ******start of body content**** </body> </html> This is my rates.php <?php echo"This is Rates page"; ?> This is my .htaccess file RewriteEngine on RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L] I really dont know if i'm doing this right...so please help me with this... thnx Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 it looks right to me but you need to update the css include line to the one i posted Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 wow! the css is fine now.... but the problem is the link....T_T when i clicked the rates link...the url looks fine and the css is doing good...but the link of the home changed...when i mouseover the home button the link is localhost/arcke/page/2....and when i click again the rates button...page not found coz the link changed to localhost/arcke/page/page/2...the "page/" became two.... whats wrong master? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 you need to change your current links / when you add new ones so when they looked like index.php they now look like /samp/index.php which is a full path from the root of your site because the browser thinks that the current page the user is viewing is in the directory /samp/title/AKO/ when really the rewrite rule is calling a page in /samp but the broswer doesn't know this so when it finds a link like "index.php" it assumes you mean in the current directory so attempts to go to /samp/title/AKO/index.php but we know this doesn't exist. but supplying the browser with a full path from your site root like /samp/index.php it then knows to go to /samp/index.php and not /samp/title/AKO/index.php Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 OMG! it works like a charm! thank you very very much master! ur such a life saver. i been messing around with this since yesterday...now i can proceed to study session...i'll just return if i have some question master! hope to see u around again here. btw, heres what im doing right now www.norsupageant.com...i hope i can make its url search engine friendly... thank you again master! more power! Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 ow i almost forgot this master.. what if i will pass another varible, and another ....so fort? let say author and address....$author and $address what should i do now? how am i going to add this in my .htaccess file? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 how may vars you want to pass i would recommend keeping it to a minimum say title and author have a look at http://www.sitepoint.com/article/apache-mod_rewrite-examples/ it should explain a few things about URL rewriting Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 ok... say i pass two variables... title and author..... what changes should i make in my php file and .htaccess file....? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 RewriteEngine on RewriteRule ^ book/([^/\.]+)/([^/\.]+)$ index.php?author=$1&title=$2 [L] and so you could get the vars like /samp/index.php <?php $author = $_GET['author']; $title = $_GET['title']; echo "Author: $author <br>"; echo "Title: $title <br>"; ?> then go to http://localhost/samp/book/Some Author/Learn PHP Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 ok the url is fine... but page not found master.... i guess there something wrong with my link... $title = "ako"; $author = "ikaw"; <a href="/arcke/title/<? echo $title; ?>/author/<? echo $author; ?>"> Rates </a> what i should i put in my link now that i pass another variable? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 4, 2009 Share Posted February 4, 2009 i did it without the "title" and "author" part so urls should look like: <a href="/arcke/<? echo $title; ?>/<? echo $author; ?>"> but if you want then to look like: <a href="/arcke/title/<? echo $title; ?>/author/<? echo $author; ?>"> then try this rewrite rule: RewriteRule ^arcke/title/([^/\.]+)/author/([^/\.]+)$ index.php?title=$1&author=$2 [L] to add another one you just have to add another part to the URL so like ^arcke/title/([^/\.]+)/author/([^/\.]+)$ would become ^arcke/title/([^/\.]+)/author/([^/\.]+)/address/([^/\.]+)$ then for the second part add another part to the url with a the next number in the sequence index.php?title=$1&author=$2&address=$3 all the ([^/\.]+) in the regex get numbered starting at $1 with a max of $9 Scott. Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 ok! everything is working very well now master! thank you so much for the time! Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted February 4, 2009 Share Posted February 4, 2009 nice site paparanch what kind of cms did you use? Quote Link to comment Share on other sites More sharing options...
paparanch Posted February 4, 2009 Author Share Posted February 4, 2009 really? ^^ actually i did not use any cms with that site... i just designed it with photoshop and code it with css. ^^ Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted February 4, 2009 Share Posted February 4, 2009 how about the photo gallery? Quote Link to comment 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.