Results 1 to 7 of 7

Thread: Apache - No Trailing Slash

  1. #1
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default Apache - No Trailing Slash

    I have a question about URL's. How do you get the URL so that it doesn't have an extension, or a trailing slash?

    I don't want this:
    /about.php
    nor this:
    /about/

    Like this:
    /about

    Here's a (completely random) URL that has no tailing slash after "about":
    http://www.alextoys.com/about

    Thanks,
    X96
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Have a look at this and see if it works for you:

    http://www.webmasterworld.com/apache/3680798.htm

    Also, a quick google search for htaccess extensionless urls is here:

    http://www.google.com/search?q=htacc...nsionless+urls

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    I tried the mod_rewrite, but it doesn't seem to work... I created a PHP document under the root dir, then went to the same filename without .php, and it just loaded the homepage...

    here's what I dumped into .htaccess::
    Code:
    Options +FollowSymlinks
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Perhaps your server is not configured with mod_rewrite, talk with your host to make sure. I tested the above code on a Hostgator account and it worked fine.
    Last edited by thetestingsite; 06-17-2009 at 02:37 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    My host has it enabled... Wordpress seems to get it to work... I'll try fiddling with what it has set up...

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  6. #6
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Never mind - I got it (a while ago I might add). I just remembered about this thread....

    Here's what I got:
    Code:
    <IfModule mod_rewrite.c>
    	RewriteEngine on
    	RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    	RewriteCond %{REQUEST_fileNAME} !-d
    	RewriteCond %{REQUEST_fileNAME} !-f
    	RewriteRule (.*) /$1.php [L]
    	RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
    	RewriteRule ^(.+)\.php$ $1 [R=301,L] 
    </IfModule>
    You can see it in action on my site too.

    Cheers,
    X96
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  7. #7
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    For ease-of-editing, I've highlighted the parts in which you need to edit if you want to change the file extension being hidden from .php (if you're using .html files, for example).
    Code:
    <IfModule mod_rewrite.c>
    	RewriteEngine on
    	RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    	RewriteCond %{REQUEST_fileNAME} !-d
    	RewriteCond %{REQUEST_fileNAME} !-f
    	RewriteRule (.*) /$1.php [L]
    	RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
    	RewriteRule ^(.+)\.php$ $1 [R=301,L] 
    </IfModule>
    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •