Trailing slash AND no file extension

Discussion in 'Apache' started by gameboyz, Jul 31, 2009.

  1. #1
    Okay I need my URLs to be short, sweet and SEO.

    I need them without the file extensions so as to be environment independent yet I want a trailing slash in case of content duplication.

    Below is what I have (does not work):
    
    #Trailing slashes
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://thinkingdays.co.cc/$1/ [L,R=301] 
    
    #Hide the file extensions
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule (.*)/?$ $1.php
    Code (markup):
    So can anybody help me come up with code that works :eek: And can somebody please explain those symbols and stuff? I've been referencing to Apache's mod_rewrite guide to try to understand the symbols and stuff but I don't really understand their usage.

    Cheers!
     
    gameboyz, Jul 31, 2009 IP
  2. gameboyz

    gameboyz Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I found a script that works, but don't understand how :)

    #No file extension
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php 
    
    #Trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    Code (markup):
    See, from my analysis it's basically saying:

    1) Enable the RewriteEngine
    2) If %{REQUEST_FILENAME} is not a directory
    3) And it is, if ".php" is added to the end, a file,
    4) Then redirect to... ? What?

    Firstly when I enter homepage.com/index/ into the URL bar I don't get redirected anywhere. But I thought RewriteRule means to redirect? And what's this for "^([^/]+)/$"

    Thanks!
     
    gameboyz, Jul 31, 2009 IP
  3. gameboyz

    gameboyz Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Bumpppppppp
     
    gameboyz, Aug 1, 2009 IP