SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Mod Rewrite Remove .php

    Hi,

    I am trying to remove the .php from the end of file names on my site. I have tried around 15 variations and contacted the host but I still cant get it to work. The thing I am puzzled about is that their are so many different options.

    DOes anyone know sure fire way to remove the .php please?


    http://css-tricks.com/snippets/htacc...comment-442471

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,150
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    A semi-helpful piece of information is that when I copy-pasted your htaccess, it worked just fine on my local server.

    But for what it's worth, before I tried it, I expected this line to fail:

    RewriteCond %{REQUEST_FILENAME}.php -f

    The reason I expected this line to fail is because you're using URLs with trailing slashes, so I expected this test to evaluate like so:

    RewriteCond /www/index/.php -f

    See how the trailing slash might cause a problem? But I have to emphasize again that this is the behavior I expected, not the behavior I saw. Apache turned out to be smart enough to discard the trailing slash (or at least the 2.4 version of Apache was).

    EDIT: Also, make sure you have this line at the beginning.

    RewriteEngine On
    "First make it work. Then make it better."

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    But I dont really understand this. Is their a standard method of removing .php?

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,150
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Thanks,

    But I dont really understand this. Is their a standard method of removing .php?
    There is, and you're doing it. Like I said, your htaccess code works fine on my local server.

    Just to make sure you're aware: As written, your non-php URLs need a trailing slash.
    "First make it work. Then make it better."

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    But I still understand. I've tried so many different options I'm confused. If I try the following code what stops it from working with my site please?


    Code:
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME}.php -f

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,150
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Those aren't the only two lines in your htaccess, are they...?
    "First make it work. Then make it better."

  7. #7
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes. I have tried lots of different options. Some 2 pages long.

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,150
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Well, the two lines you just posted won't work by themselves, because there aren't even any rewrite rules in there. But the htaccess you linked to in your first post seems to work just fine on my local server, except that I added the RewriteEngine On line.
    "First make it work. Then make it better."

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    You mean this one. The one produced by blog?

    Code:
    RewriteRule ^about$ about.php [L]
    Could you please detail the code that should be used? I would be very grateful.

  10. #10
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does anyone have any suggestions please on how I can fix this. It appears simple but what ever I try doesn't seem to work.


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
  •