Wordpress mod rewrite problem

Discussion in 'PHP' started by myinnet, Dec 6, 2008.

  1. #1
    i have installed wordpress on my site, i have used the built in modrewite, when i post a item, the url is like:
    http://www.domain.com/my-item/
    the url is works well with the following code:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]


    and i have add my file to the blog, the file is search.php, and i want turn
    http://www.domain.com/search.php?name=search word
    to
    http://www.domain.com/search_word.html

    so i added this line to the .htacess file
    RewriteRule ([0-9a-zA-Z_???]*).html /search.php?name=$1
    but it will not works, can anyone help me how to write this code?
    thanks
     
    myinnet, Dec 6, 2008 IP
  2. zdrol

    zdrol Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I tested this and it works.
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([A-Za-z0-9_]*)\.html$ /search.php?name=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    Code (markup):
    The placement of the custom rewrite rule is important

    IF you (temporarily) can change it to

    RewriteRule ^([A-Za-z0-9_]*)\.html$ /search.php?name=$1 [R,L]

    It will redirect and you can see in the location bar how the url is being rewritten and tweak as needed.
     
    zdrol, Dec 6, 2008 IP
  3. myinnet

    myinnet Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks so much, it works well. Thanks soooooo much :) You are BIG helper
     
    myinnet, Dec 6, 2008 IP