View Full Version : Apache - No Trailing Slash
X96 Web Design
06-17-2009, 01:22 AM
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
thetestingsite
06-17-2009, 02:24 AM
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=htaccess+extensionless+urls
Hope this helps.
X96 Web Design
06-17-2009, 02:42 AM
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::
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
// X96 \\
thetestingsite
06-17-2009, 02:24 PM
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.
X96 Web Design
07-03-2009, 07:56 PM
My host has it enabled... Wordpress seems to get it to work... I'll try fiddling with what it has set up...
// X96 \\
X96 Web Design
07-22-2009, 02:58 PM
Never mind - I got it (a while ago I might add). I just remembered about this thread....
Here's what I got:
<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 (http://x96webdesign.uuuq.com/) too. :)
Cheers,
X96
X96 Web Design
12-31-2009, 01:05 AM
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).
<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 \\
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.