Jared Codling
Jared Codling

Reputation: 43

How do I make my Htaccess remove Extension, while not having a filename after directories

I'm coding in PHP, and have implemented a htaccess code which removes the file extension (in this case '.php').

The problem is, this doesn't allow directories to remove the index.php on the end.

I.E. http://www.domain.com/about/ - The requested URL /about/.php was not found on this server.

Here is my current code:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.domain.com/$1 [R=301,L]

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php/?$ / [L,R=301,NC]

I want to have /about/ redirect to /about/index.php, while just showing /about/

Thanks in advance guys!

Upvotes: 1

Views: 112

Answers (1)

user1000456
user1000456

Reputation:

just use DirectorySlash in htaccess file apatche automatically appends trailing slash after directory names

DirectorySlash On

if you want call the directory without the trailing slash try:

DirectorySlash Off

Upvotes: 1

Related Questions