WEB the trailing slash problem

Discussion in 'OT Technology' started by White Stormy, Aug 5, 2008.

  1. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,486
    Likes Received:
    69
    Location:
    Sparkopolis
    http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
     
  2. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,486
    Likes Received:
    69
    Location:
    Sparkopolis
    however, neither of those is a solution for dynamic links that don't have a physical representation on the drive.. so I came up with this

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+[^/])$ $1/ [R]
    
    but this still requires a RewriteBase before it.. so what other options are there?
     
  3. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,486
    Likes Received:
    69
    Location:
    Sparkopolis
    oh I just realized you can just use
    Code:
    RewriteBase /
    in the root .htaccess and it'll work.. well is that the best way?
     
  4. Divine Vengeance

    Divine Vengeance New Member

    Joined:
    May 21, 2003
    Messages:
    20,453
    Likes Received:
    0
    My grasp of regex is basic at best, I've been doing something similar where any url that doesnt end in a file extension (.css, .php, .js, .png, etc etc) is given a trailing slash

    Code:
    # Allow rewriting URLs
     RewriteEngine on
     
    # Base directory 
     RewriteBase    /ktv4/
     
    # add trailing slash to directory-based requests
     RewriteCond 	 %{REQUEST_URI} !^(.*)/(.*)\.((.*)+[^/])$
     RewriteRule     ^(.+[^/])$ 	$1/  [R]
    
    # Don't rewrite requests for files in non-navigational directories
     RewriteCond 	%{REQUEST_URI} !^(.*)?/(static|include|content)/(.*)(/)?$ 
     RewriteRule 	^([a-z]+)/([a-z]+)?/?(.*)?(/)?$  index.php?x=$1&sub=$2&null=$3
     
    The second half is just a standard navigational redirect for anything requested outside certain dirs. I fully expect it to be laughed at by anyone else who is more experienced with regex, but it might be a good start for you.
     
  5. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,486
    Likes Received:
    69
    Location:
    Sparkopolis
    I can usually come up with regex stuff that works, but I'll get multiple answers and I don't know hot apache evaluates them to know which is the fastest

    I was trying to do that.. anything that didn't have a file extension on the end.. but didn't think to use a condition.. I was trying to do it as a standalone rule.. got complicated.
     

Share This Page