Directory Style ModRewrite ?

Discussion in 'Apache' started by strogg, Jul 21, 2007.

  1. #1
    I have url's like this ;
    
    http://localhost/project/showpage.php?page=avas
    
    Code (markup):
    But I want like this
    
    http://localhost/project/avas
    
    Code (markup):
    when i use webmaster-toolkit's rewrite tool, it generates, this codes
    
    http://localhost/project/showpage/page/avas/
    
    Code (markup):
    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule showpage/(.*)/(.*)/$ /project/showpage.php?$1=$2
    
    Code (markup):
    But I dont want "showpage" and "page" element on url , just clean
    
    http://localhost/project/avas
    
    Code (markup):
    is this possible and if possible how can i use custom code for this ?
     
    strogg, Jul 21, 2007 IP
  2. strogg

    strogg Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i solved first part

    Options FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.{2,5} [NC]
    RewriteRule ^([^/]+)/$ /project/showpage.php?page=$1& [L,NC]

    but if typed.

    http://localhost/project/avas - gives 404 error

    else

    http://localhost/project/avas/ - it will work

    so how can i add automatic trailing slash's end of the url ?
     
    strogg, Jul 21, 2007 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^project/([^.]+)/$ project/showpage.php?page=$1 [L]
    RewriteRule ^project/([^.]+)$ project/showpage.php?page=$1 [L]

    both with and with out da /.
     
    Nintendo, Jul 21, 2007 IP
  4. strogg

    strogg Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for reply, but still wont work, your code gives "Server error".

    How can i add a line for fixing trailing slash problem, for this code ?


    Options FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.{2,5} [NC]
    RewriteRule ^([^/]+)/$ showpage.php?page=$1& [L,NC]
     
    strogg, Jul 22, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    Options FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.{2,5} [NC]
    RewriteRule ^([^/]+)/$ showpage.php?page=$1& [L,NC]
    RewriteRule ^([^/]+)$ showpage.php?page=$1& [L,NC]
     
    Nintendo, Jul 23, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Just add a question mark to have an optional trailing slash, that way, you only need 1 rule ;)
    RewriteRule ^([^/]+)/?$ showpage.php?page=$1& [L,NC]
    Code (markup):
     
    krt, Jul 23, 2007 IP
  7. strogg

    strogg Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    working now, thanks
     
    strogg, Jul 23, 2007 IP