Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21

Thread: mod_rewrite simple tutorial

  1. #1
    melkior_inactive Guest

    Default mod_rewrite simple tutorial

    Ok, mod rewrite is very good function of Apache Web Server.
    The potential is enormous. As you might or might not know, I'm developing a link selling app for UK WW.
    And we want the app to be SEO friendly.
    So this is a potential use of mod rewrite.
    It's also good if you want to hide the structure of your website, and the arguments that you pass to the script.

    So what does it look like?
    Well this is the basic idea:
    you have a site called www.domain.com
    and you have a script which passes the arguments.
    So your url look like this:
    www.domain.com/index.php?query=xxx&id=yyy

    mod rewrite enables you to change that into:
    www.domain.com/xxx/yyy/

    First of all make sure that mod_rewrite is available on your server and turned on.
    You can check that out by creating a file (let's call it phpinfo.php) with the following content:
    PHP Code:
    <? phpinfo(); ?>
    Go to that page and search for mod_rewrite. If you find it you're good to go.
    If not, contact your host.

    OK, now create a .htaccess file with this content:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(.*)/(.*)/$ index.php?query=$1&id=$2 [L]
    Upload the file to your server into the folder that contains the script.
    Now, what this does is: when someone requests bla/bla/ on your server, it automatically gets transcribed to index.php?query=bla&id=bla
    Cool, isn't it?

    But maybe you want your site to look like this:
    www.domain.com/xxx-yyy.html
    No problem!
    This is the setup for the .htaccess file:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(.*)-(.*).html$ index.php?q=$1&id=$2 [L]
    So if you need index.php?query=bla&id=bla you can now access it like bla-bla.html

    Now, all you need to do is update the links in your site and your site is SEO friendly and harder to hack.
    Here's a little help with that. If you have static links you have no problems, but chances are that your script is generating the urls based on various conditions.
    So here's the old code:
    PHP Code:
    <html>
    <body>
    ...
    ...
    <?
    echo '<a href="$siteurl/index.php?query=type&id=$id">Link</a>';
    ?>
    You'd change it to:
    PHP Code:
    <html>
    <body>
    ...
    ...
    <?
    echo '<a href="$siteurl/type/$id/">Link</a>';
    ?>
    for the first type of url rewrite.
    Or:
    PHP Code:
    <html>
    <body>
    ...
    ...
    <?
    echo '<a href="$siteurl/type-$id.html">Link</a>';
    ?>
    for the second type.
    Hope it helps.

  2. #2
    temi's Avatar
    temi is offline Facilitator temi is just really nice temi is just really nice temi is just really nice temi is just really nice temi is just really nice
    Join Date
    Jun 2003
    Location
    London, England.
    Posts
    10,304

    Default

    Excellnet tutorial Melky

    * Build a shopping cart for your business with eCommerce software UK
    * BossCart.com can build you a.
    Register your domain names at Velnet
    ::
    Add Eco sites to The Green Directory free of charge.
    Use LBS Free PHP Directory Script . Web Hosting Blog

  3. #3
    melkior_inactive Guest

    Default

    Thanks Temi!
    Hope our members will find it useful.
    If anyone has questions don't be afraid to ask.

  4. #4
    Bagi Zoltán's Avatar
    Bagi Zoltán is offline Boss Cart consultant Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of
    Join Date
    Feb 2007
    Location
    Veszprém, Hungary
    Posts
    1,225

    Default

    Wow Melkior, I don't say that I would become a htaccess genius, but your tutorial do really helps a lot to understand this rewrite thing.
    Rep added, thank you

  5. #5
    melkior_inactive Guest

    Default

    Bagi, I am more than pleased if you get anything useful from these ramblings!
    I'll add a few more examples and suggestions tomorrow.

  6. #6
    Bagi Zoltán's Avatar
    Bagi Zoltán is offline Boss Cart consultant Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of Bagi Zoltán has much to be proud of
    Join Date
    Feb 2007
    Location
    Veszprém, Hungary
    Posts
    1,225

    Default

    That is very kind of you. I didn't understand this topic so far because i couldn't connect it with php, but you gave examples how to modify the php file also.

  7. #7
    melkior_inactive Guest

    Default

    I promised to add a few more explanations but never got back to do them.
    Now, when I see how many linkbacks this thread has I think I'll try to explain a few more things.

    In the first part of the tutorial I gave examples how to change your dynamic link structure too look like a directory structure or an HTML pages structure.

    These are the two most common examples, but truth is you'll probably want a combination of these two.

    So you want your www.domain.com/index.php?query=xxx&id=yyy to look like this:
    www.domain.com/xxx/yyy.html

    How do you achieve this?
    Your .htaccess file should look like this:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(.*)/(.*).html$ index.php?query=$1&id=$2 [L]
    And your links update in the PHP script should be something like:
    PHP Code:
    <html>
    <body>
    ...
    ...
    <?
    echo '<a href="$siteurl/type/$id.html">Link</a>';
    ?>
    This makes your site not only SEO friendly but human friendly too.

  8. #8
    lala is offline Senior Member lala is on a distinguished road
    Join Date
    Feb 2007
    Posts
    145

    Default

    Melkior,

    Better later than never:
    Thank you so much for this marvellous post Your knowledge on this is really impressive and I learned (again) a lot...

    lala

  9. #9
    mrcrowley's Avatar
    mrcrowley is offline Senior Member mrcrowley is just really nice mrcrowley is just really nice mrcrowley is just really nice mrcrowley is just really nice mrcrowley is just really nice
    Join Date
    Apr 2007
    Posts
    360

    Default

    Sorry for being a newb (I tried to figure it out myself before posting).
    Where in your site might you find the php script which you enter the following code into?

    I'm trying to implement this into this site... A2Z Sex Shop - His And Her Sex Toys, Dildos, Strapons, Dolls, Bondage kits

    Thanx!

    Quote Originally Posted by melkior View Post
    And your links update in the PHP script should be something like:
    PHP Code:
    <html>
    <body>
    ...
    ...
    <?
    echo '<a href="$siteurl/type/$id.html">Link</a>';
    ?>
    This makes your site not only SEO friendly but human friendly too.

  10. #10
    temi's Avatar
    temi is offline Facilitator temi is just really nice temi is just really nice temi is just really nice temi is just really nice temi is just really nice
    Join Date
    Jun 2003
    Location
    London, England.
    Posts
    10,304

    Default

    Jamie,
    What application did you use to create your shop?

    * Build a shopping cart for your business with eCommerce software UK
    * BossCart.com can build you a.
    Register your domain names at Velnet
    ::
    Add Eco sites to The Green Directory free of charge.
    Use LBS Free PHP Directory Script . Web Hosting Blog

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. simple php contact form
    By OldDarkstarAccount in forum Download Section
    Replies: 11
    Last Post: 10-01-2009, 07:00 PM
  2. A simple exercise
    By OldWelshGuy in forum Directories
    Replies: 6
    Last Post: 02-15-2007, 09:13 AM
  3. Simple guide to CSS
    By Rifat in forum General Webmaster Talk
    Replies: 8
    Last Post: 05-03-2006, 07:19 AM
  4. ISO to UTF-8 Tutorial
    By clau in forum General Webmaster Talk
    Replies: 0
    Last Post: 12-30-2005, 04:54 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124