SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question how to slug my url?

    Dear all
    i read some online tutorial and i want to do seo my url but it not working any idea for it? my slug code below
    PHP Code:
    <?php
    setlocale
    (LC_ALL'en_US.UTF8');
    function 
    slug_url($str) {
        
    $clean iconv('UTF-8''ASCII//TRANSLIT'$str);
        
    $clean preg_replace("/[^a-zA-Z0-9\/_| -]/"''$clean);
        
    $clean strtolower(trim($clean'-'));
        
    $clean preg_replace("/[\/_| -]+/"'-'$clean);
        return 
    $clean;
    }
    ?>
    and the url i want to do it is
    http://www.sabaychet.com/articledeta...to-make-an-suv
    when i used slug my url become
    http://www.sabaychet.com/articledeta...to-make-an-suv
    -------
    The requested URL /articledetailphpph-sc-art-titleenvolkswagen-bentley-to-make-an-suv was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    -----------------
    can not find the information so how to sold this problem?
    Best regards,
    Heng

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    If your original URL is /articledetail.php?ph_sc_art_titleen=volkswagen-bentley-to-make-an-suv then I'm guessing that you actually want your friendly URL to be /articles/volkswagen-bentley-to-make-an-suv or maybe even /volkswagen-bentley-to-make-an-suv?

    In any case, what you need to do is change your .htaccess file (or create one, if it doesn't exist) in your web root directory, and do something like this:
    Code:
    <IfModule mod_rewrite.c>
      # Turn on URL rewriting
      RewriteEngine On
    
      # Installation directory
      RewriteBase /
    
      # Allow any files or directories that exist to be displayed directly
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
    
      # Rewrite article URLs to articledetail.php
      RewriteRule ^articles/(.*)$ articledetail.php?ph_sc_art_titleen=$1
    </IfModule>

  3. #3
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    hengwebdeveloper, please can you post here and not by private message. If my suggestion isn't working for you, can you describe what you're doing and what errors you're getting, and then I (or others) can help you.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    fretburner, i was copy and past your code into my .htaccess file it not working do i need to use slug and .htaccess both?

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by hengwebdeveloper View Post
    fretburner, i was copy and past your code into my .htaccess file it not working do i need to use slug and .htaccess both?
    Yes, you need both. Your code generates the friendly URL, and the rewrite rules in .htaccess translate those URLs into instructions to the server about which file to load.

    When you say it's not working, are you getting a 404 not found error or something?

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    yeah it getting error because the url need articledetail.php to execute the code does my slug it right? or where the wrong part?

  7. #7
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    OK, so I've got a couple things you can try.

    Edit your .htaccess file and try adding this line at the top (above the <IfModule mod_rewrite.c> line):
    Code:
    Options -MultiViews
    If that doesn't work, you could also try editing this line:
    Code:
    RewriteRule ^articles/(.*)$ /articledetail.php?ph_sc_art_titleen=$1
    Notice that I've added a / before articledetail.php - this seems to make a difference on some servers.

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    no it still not working because it need 1 file to execute code

  9. #9
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    I thought you already had a file called articledetail.php.. but now you're saying that you don't? In that case, just start with something like this to check that it's working:
    PHP Code:
    <?php

    var_dump
    ($_GET);
    Then you can try going to http://www.sabaychet.com/articles/volkswagen-bentley-to-make-an-suv or whatever your URL is.


Tags for this Thread

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
  •