Forum Moderators: phranque

Message Too Old, No Replies

Removing .php from files and having directories with the same name

         

bjornenke

6:04 am on Nov 19, 2008 (gmt 0)

10+ Year Member



Hello,

I have spent all day reading, mostly on this website, trying to figure out how to make my previously working redirects work under Apache 2.2.X as my host recently upgraded.

Primarily, I used mod rewrite to remove .php from the end of files. However, I also had it working so that www.example.com/topic would work without returning a 403 error even though a directory at www.example.com/topic/ exists without an index.php file inside it. (Basically, Apache wouldn't look for /topic/index.php, but rather for /topic.php and remove the .php) I hope this makes sense.

The line that seems to no longer work (bolded in the code below) was something I came up with to allow for what I explained above. It seems like it may have been the wrong way to tell Apache to look for a file with the same name as a directory ather than inside the directory for it's index file, especially since it no longer works, but any tips or suggestions would be greatly appreciated.

--------------------------------

# MOD REWRITE

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301]

#removes .php
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

#removes "index"
RewriteRule (.*)/index$ $1 [R=301]

#removes "/"
RewriteRule (.*)/$ $1 [R=301]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

------------------------------------

phranque

11:14 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], bjornenke!

jdMorgan

2:06 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since you've added the new RewriteCond checking THE_REQUEST for a trailing slash, you can delete the RewriteCond that checks $1 for a trailing slash on the line above your new RewriteCond. Your new RewriteCond will cover all the cases that the old one did, as well as the 'home page' case.

Jim

bjornenke

8:22 am on Dec 16, 2008 (gmt 0)

10+ Year Member



Thanks Jim!

I really appreciate all your help with this. Thanks so much!

This 33 message thread spans 2 pages: 33