SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: mode rewrite code

  1. #1
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mode rewrite code

    http://www.mysite.com/folder/page.ph...2=var2&c3=var3

    I want to display my page as

    www.mysite.com/folder/var1/var2-var3.html

    What will be code for mode rewrite (.htaccess) . Anybody can help me?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,

    I'd be happy to help - if you would show what you've attempted.

    It looks to be trivial - at least it would be if you've read the tutorial Article linked in my signature.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    RewriteEngine on
    
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/$
    index.php?c1=$1&c2=$2&c3=$3 [NC,L]
    <a href="http://www.mysite.com/folder/var1/var2-var3.html


    but not working. (404 Error)

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,

    Thanks! That makes the error pretty easy to spot!
    Code:
    RewriteEngine on
    
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)-([a-zA-Z_]+)/$
    index.php?c1=$1&c2=$2&c3=$3 [NC,L]
    With <a href="http://www.mysite.com/folder/var1/var2-var3.html"> as your link, I've replaced the second directory dividing / in your regex with a blue hyphen (-) and recommend that you remove the red No Case flag as you've already covered that with the a-zA-Z in the regex (and your script should be handling that).

    It's simply a matter of specifying what the link will be. With that, the regex becomes a simple matter.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not working (404 Error)

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,

    Test URL? Specificity, please, as it REALLY helps when we're trying to help you.

    If it's the var1, etc, then you'll need to add digits to your character ranges, i.e., each [a-zA-Z_] should become [a-zA-Z0-9_].

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my file (2index.php)
    Code:
    <a href="http://www.ouchh.com/Weather/europe/england-london.html" >London Weather</a>
    <br><br>
    <?php
    
    $c1 = $_GET['c1'];
    $c2 = $_GET['c2'];
    $c3 = $_GET['c3'];
    $c4 = $_GET['c4'];
    $c5 = $_GET['c5'];
    
    echo $c1;
    echo $c2;
    echo $c3;
    echo $c4;
    echo $c5;
    
    ?>

    This is my .htaccess
    Code:
    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)-([^/]*)\.html$ 2index.php/?c1=$1&c2=$2&c3=$3&c4=v4&c5=v5 [L]

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,

    The URL you provided does not match the problem defined above. Moreover, your mod_rewrite code ignores all of the above.
    Code:
    RewriteEngine on
    
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)-([a-zA-Z_]+)$
    index.php?c1=$1&c2=$2&c3=$3&c4=$4 [L]
    SPECIFICITY, please!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what is the solution for my problem.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by rashidr View Post
    so what is the solution for my problem.
    rash,

    You actually need to try the code I put in this thread. You might be surprised that it works.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    433
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you developing this on your local machine, or on a live server?

  12. #12
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried, but (404 page not found) error receiving

    Are you developing this on your local machine, or on a live server?
    On Live server

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,

    Are you redirecting to index or 2index for this? Change to 2index if that's the correct script (and can be found).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  14. #14
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am redirecting to index.php

  15. #15
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    rash,
    Code:
    RewriteEngine on
    
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)-([a-zA-Z_]+)/$
    index.php?c1=$1&c2=$2&c3=$3 [NC,L]
    That should work for your original post.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

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
  •