Jump to content

Search Engine Friendly URL using htacces.....need help


paparanch

Recommended Posts

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!

 

 

 

Link to comment
Share on other sites

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>


Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

 

 

 

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.