help for URL / mod-rewrite ?

Discussion in 'PHP' started by kemonrider, Sep 24, 2010.

  1. #1
    hello,

    i need help. i have a bit problem for my site.

    i want to rewrite my permalink URL from this :

    mysite.com/detail.php?title={Article Title}

    to this :

    mysite.com/{Article Title}


    and if visitor use this URL :

    mysite.com/{Article Title}

    it will be processed by the detail.php?title={Article Title}


    thank you.
     
    kemonrider, Sep 24, 2010 IP
  2. riteshsanap

    riteshsanap Well-Known Member

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    168
    #2
    If you use Apache server, you can add something like this in your .htaccess file

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
    Code (markup):
    This is just a sample. Adjust it to fit your need. Whatever in the URL will calls to "index.php". Then you can read the url from $_SERVER['REQUEST_URI'] and to load whatever content you need.
     
    riteshsanap, Sep 24, 2010 IP
  3. HungryMinds

    HungryMinds Active Member

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #3
    Hi!

    Try These Commands:

    
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^articletitle/ /detail.php?title=articletitle
    
    ErrorDocument 404 http://www.yousite.com/
    ErrorDocument 403 http://www.yousite.com/
    ErrorDocument 500 http://www.yousite.com/
    ErrorDocument 401 http://www.yousite.com/
    
    Code (markup):
     
    HungryMinds, Sep 24, 2010 IP
  4. kemonrider

    kemonrider Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    wow, thanks !
    i'am still ab it confused, but will try it trough.
    Thanks

    wow..nice, gonna try it.
    Thanks
     
    kemonrider, Sep 24, 2010 IP
  5. kemonrider

    kemonrider Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    still getting 404 Page not found.

    please help :(
     
    kemonrider, Sep 24, 2010 IP
  6. HungryMinds

    HungryMinds Active Member

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #6
    Well! Create a Page For "404"

    Like: "sorry.php"

    ErrorDocument 404 http://www.yousite.com/sorry.php

    Or U Can Redirect It To Your Home Page With Full Path.

    ErrorDocument 404 http://www.yousite.com/

    But! Be Sure It's 404 Else Use Other ErrorDocument Code Like 403, 500, 401 etc...
     
    HungryMinds, Sep 24, 2010 IP
  7. kemonrider

    kemonrider Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yes, i have make a 404 page.

    but, the main rewrite is not functioning.
    when i test mysite.com/title1 , the result is 404.
     
    kemonrider, Sep 24, 2010 IP
  8. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If your mod-rewrite is available,pls try to put below code in your .htaccess file:

    RewriteEngine On
    RewriteRule ^(.*?)$ detail.php?title=$1 [L]
     
    sunlcik, Sep 24, 2010 IP
  9. kemonrider

    kemonrider Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    SOLVED !

    thanks for all the inputs.

    the code i use :

    and it done beautifully.
     
    kemonrider, Sep 24, 2010 IP