1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[ASK] Cara Membuat Clean URL Wordpress Permalink

Discussion in 'Pemrograman Web' started by andiklive, Sep 23, 2013.

  1. andiklive

    andiklive Super Hero

    Joined:
    Feb 4, 2012
    Messages:
    1,569
    Likes Received:
    103
    Location:
    Kurniawan Technologies
    selamat sore agan2 ads-id,
    langsung saja, saya mempunyai kendala pada blog saya.
    begini ceritannya, permalink wordpress saya kan sudah saya custom lewat script php.
    nah pertanyaanya gimana caranya bikin clean url yang "moved permanently"
    dan naruh script itu pada file apa, kayak function.php atau malah .htaccess

    misal url saya
    Code:
    sample.com/article--cara-rubah--url-.html 
    dapat diubah menjadi
    Code:
    sample.com/article-cara-rubah-url.html 
    nah menurut ane ake str_replace atau trim, tapi gimana solusinya dan implementasinya gimana pada wordpress?
    thanks agan2 ads-id
     
  2. kacamatagaya

    kacamatagaya Research Keyword Service

    Joined:
    Mar 26, 2011
    Messages:
    314
    Likes Received:
    26
    Location:
    Masih di Bumi
    Aduh pertanyaan agan berat bgt :D

    mksdnya mau ganti url post yang sudah diposting ya...

    Kalo di wordpress, coba masuk ke setting >> permalink

    View attachment 33612

    kyk gambar diatas bro... sorry kalo ga nyambung :D
     
    andiklive likes this.
  3. nasdin

    nasdin Super Hero

    Joined:
    May 28, 2013
    Messages:
    806
    Likes Received:
    182
    simple

    PHP:
    $str 'article--cara-rubah--url-';
    $link str_replace('_','-',$str);
    $link sanitize_title_with_dashes($link);
    header('HTTP/1.1 301 Moved Permanently');
    header('location: http://sample.com/' $link '.html');
    advance :

    http://stackoverflow.com/a/4054740 copy functionnya di functions.php

    PHP:
    $str 'Häßliches murciélago hindú comía fe<!>&@#$%&!"#%&?¡?*liz cigüeña ¨^;.-|°¬ saxofón detrás  --cara-rubah--url-_';
    $link friendlyUrl($str);
    header('HTTP/1.1 301 Moved Permanently');
    header('location: http://sample.com/' $link '.html');
     
    andiklive likes this.
  4. kacamatagaya

    kacamatagaya Research Keyword Service

    Joined:
    Mar 26, 2011
    Messages:
    314
    Likes Received:
    26
    Location:
    Masih di Bumi

    Mastah nya turun nih :D
     
  5. andiklive

    andiklive Super Hero

    Joined:
    Feb 4, 2012
    Messages:
    1,569
    Likes Received:
    103
    Location:
    Kurniawan Technologies
    thanks agan @kacamatagaya dan agan @nasdin atas bantuanya.
    trus gimana caranya tiap ada http request dengan url yang belum di sanitize tersebut
    langsung redir ke url yang sudah di sanitize tersebut pada wordpress.

    oh iya fungsi sanitize_title_with_dashes kok gak work yah, ada referensi seperti ini
    Code:
    sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' );
    kalau search_structure pada wordpress udah saya rubah, yang http request ini saya kurang paham.
     
  6. andiklive

    andiklive Super Hero

    Joined:
    Feb 4, 2012
    Messages:
    1,569
    Likes Received:
    103
    Location:
    Kurniawan Technologies
    oh iya, kalau lewat .htaccess bisa atau tidak.
    soalnya yang saya mau clean url yang urlnya belakangnya ada ".html"
    sedangkan untuk pages saya pake sample. com/page/pages
    soalnya url yang ada .html di generate secara auto.
     
  7. nasdin

    nasdin Super Hero

    Joined:
    May 28, 2013
    Messages:
    806
    Likes Received:
    182
    saya ambil contoh default wp yg pakai variable 's' ketika search

    sample.com/?s=+article+cara+++rubah+url

    kan katanya pake header redirect, berarti naruhnya di search.php kan?
    PHP:
    $str $_GET['s']; 
    $link str_replace('_','-',$str); 
    $link sanitize_title_with_dashes($link); 
    header('HTTP/1.1 301 Moved Permanently'); 
    header('location: http://sample.com/' $link '.html');
    karena pake header redirect, tentunya rewrite.php & query.php udah diedit dong?

    jadi ga ada proses edit htaccess kan di sini?

    atau kalo mau yg lebih simple prosesnya saya kira bisa pake modifan dari ini http://www.ads-id.com/forums/showthread.php/158728#post2071653
     
    andiklive likes this.
  8. aswandaalifian

    aswandaalifian Ads.id Pro

    Joined:
    Sep 24, 2013
    Messages:
    259
    Likes Received:
    24
    Location:
    Purwokerto Selatan, Banyumas
    sangat bermanfaat mastah, untuk saya yg masih newbie
     
  9. andiklive

    andiklive Super Hero

    Joined:
    Feb 4, 2012
    Messages:
    1,569
    Likes Received:
    103
    Location:
    Kurniawan Technologies
    thanks agan nasdin, iya setelah saya coba ternyata gak perlu pake .htaccess cukup di headernya saja.
    terimakasih banyak atas sharenya :)
     
    Last edited: Sep 24, 2013
  10. Kireleous

    Kireleous Newbie

    Joined:
    Oct 4, 2013
    Messages:
    19
    Likes Received:
    0
    akhirnyaaa thanks agan-agan senior, atas comment2nya jd bisa jg ane hehe
     

Share This Page