RewriteRule help

Discussion in 'PHP' started by mcnika, Apr 7, 2010.

  1. #1
    Hello.
    I need convert dynamic url to static.
    I have

    domainname.com/?m=view&id=2

    $_GET['m'] is an page name that will be included in index.php.

    i.e. include($_GET['m'].".php");

    I need to convert url to
    domainname.com/view/2.html
    or
    domainname.com/view/2
     
    mcnika, Apr 7, 2010 IP
  2. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try that should work perfect

    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^/view/(.*)$ /index.php?m=view&id=$1 [L]
    
    Code (markup):
     
    atlantaazfinest, Apr 7, 2010 IP
  3. mcnika

    mcnika Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    all code that is written in index.php does't show.
    And when I echo $_GET['id'] in the view.php - is said Undefined index: id
     
    mcnika, Apr 10, 2010 IP
  4. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Post up your php code
     
    atlantaazfinest, Apr 12, 2010 IP
  5. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #5
    Try this for domainname.com/view/2 rewrite:
    
    RewriteEngine On
    Options +FollowSymLinks
    
    DirectoryIndex index.php
    
    RewriteRule ^view/([^/]*)$ /index.php?m=view&id=$1 [L]
    
    Code (markup):
    This should be placed in the .htaccess file of your root directory.
     
    nimonogi, Apr 12, 2010 IP