1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

mod_rewrite for "site.com/foo" and "site.com/foo/bar" ?

Discussion in 'Apache' started by Skeleton, Mar 11, 2006.

  1. #1
    Skeleton, Mar 11, 2006 IP
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Try this (not tested) :
    RewriteEngine on
    RewriteRule ^([a-z]+)$ /index.php?var1=$1  [L]
    RewriteRule ^([a-z]+)\/([a-z]+)$ /index.php?var1=$1&var2=$2  [L]
    Code (markup):
    This assumes that foo and bar can only contain lower case letters.

    Jean-Luc
     
    Jean-Luc, Mar 11, 2006 IP
  3. SpeedyDomainRegistration

    SpeedyDomainRegistration Peon

    Messages:
    170
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    for lower and upper case.

    
    RewriteEngine on
    Options +SymLinksIfOwnerMatch
    RewriteBase /
    RewriteRule ^([aA-zZ]+)/(aA-zZ]+)$ index.php?var1=$1&var2=$2 [L]
    RewriteRule ^(aA-zZ]+)$ index.php?var1=$1 [L]
    
    Code (markup):
    If url will contain upper and lower case.
    If problem, server may require leading /

    
    RewriteEngine on
    Options +SymLinksIfOwnerMatch
    RewriteBase /
    RewriteRule ^/([aA-zZ]+)/(aA-zZ]+)$ index.php?var1=$1&var2=$2 [L]
    RewriteRule ^/(aA-zZ]+)$ index.php?var1=$1 [L]
    
    Code (markup):
     
  4. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Skeleton, Mar 11, 2006 IP
  5. SpeedyDomainRegistration

    SpeedyDomainRegistration Peon

    Messages:
    170
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try to see if this works.

    
    RewriteEngine on
    Options +SymLinksIfOwnerMatch
    RewriteBase /
    RewriteRule ^(.*)/(.*)$ index.php?var1=$1&var2=$2 [L]
    RewriteRule ^(.*)$ index.php?var1=$1 [L]
    Code (markup):
     
  6. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    @SpeedyDomainRegistration

    I had already tried that.

    But I have found the way to do this

    This has worked like a charm. I have found this via http://wettone.com/code/clean-urls and modified it a little. Thanks all anyway.
     
    Skeleton, Mar 11, 2006 IP
  7. VizMeta

    VizMeta Well-Known Member

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #7
    does anyone know a way to use mod_rewrite to replace spaces (%20) in the url and replace them with a dash (- or ~)?

    any help on this would be most appreciated...
     
    VizMeta, Mar 11, 2006 IP
  8. SpeedyDomainRegistration

    SpeedyDomainRegistration Peon

    Messages:
    170
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Here it is:

    
    RewriteRule ^([[:alnum:]]+)[[:space:]]([[:alnum:]]+).([[:alpha:]]+)$ http://www.somedomain.com/$1-$2.$3 [NC,R=301,L]
    
    Code (markup):
    more at http://www.webmasterworld.com/forum92/317.htm

    Only work with 1 space in url
     
  9. VizMeta

    VizMeta Well-Known Member

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #9
    thanks for the heads up...

    looks like this one is going to be tricky...
     
    VizMeta, Mar 11, 2006 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    Make the script search for spaces and change them in to -. Then you don't need to make mod_rewrite do it. (You would need to know php to edit the script!)
     
    Nintendo, Mar 11, 2006 IP