Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Hide file extension .htaccess

    I've been trying to hide my .php file extension using .htaccess, but I can't seems to get it working. I want to be able to visit my pages without typing the .php part and without .php showing in the url. Like:

    http://www.example.com/events.php

    vs

    http://www.example.com/events

    I've been trying the following, but I can't get it to work:

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    It always says page not found.

  • #2
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    any ideas why this won't work for me?

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I've tried a bunch of different solutions, but I can't make it work. Any help would be great.

  • #4
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Try this.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [QSA]

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Microsuck View Post
    Try this.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [QSA]
    Thanks for the reply. This does remove the extension, however it doesn't go to the right page. If I type http://www.mysite.com/about it shows that as the url but goes to the index page instead of the about page.

  • #6
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sankou View Post
    Thanks for the reply. This does remove the extension, however it doesn't go to the right page. If I type http://www.mysite.com/about it shows that as the url but goes to the index page instead of the about page.
    My apologies!

    I *think* this will work.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /*.php?$1 [QSA]
    If that doesn't work, try this:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ *.php?$1 [QSA]
    I am just learning how to play with htaccess, so sorry if none of this works.

  • #7
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Microsuck View Post
    My apologies!

    I *think* this will work.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /*.php?$1 [QSA]
    If that doesn't work, try this:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ *.php?$1 [QSA]
    I am just learning how to play with htaccess, so sorry if none of this works.
    I tried them, I get a 500 internal service error with both.

  • #8
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sankou View Post
    I tried them, I get a 500 internal service error with both.
    Give this a try

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ .php?$1 [QSA]

  • #9
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Microsuck View Post
    Give this a try

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ .php?$1 [QSA]
    I'm still getting the 500 internal service error

  • #10
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    I'm just striking out.

    A few more tries before I give up.

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

  • #11
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I think I got it working. I switched the last line to

    Code:
    RewriteRule ^(.*)$ /$1.php
    From what I understand, it takes whats after the / and stores it in $1. So if I were to navigate to mysite.com/about the last line forwards it to mysite.com/$1.php. The $1 in this case is about. Is this right?

  • #12
    New Coder
    Join Date
    Oct 2011
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Microsuck View Post
    I'm just striking out.

    A few more tries before I give up.

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    Yes, I saw this after my last post. Mine just had a slash before $1. Thanks so much for your help!

  • #13
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sankou View Post
    Yes, I saw this after my last post. I think this would work as well. Mine just had a slash before $1. Thanks so much for your help!
    No problem! Sorry it took so long!

  • Users who have thanked Microsuck for this post:

    sankou (10-25-2011)


  •  

    Posting Permissions

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