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 2 of 2
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Friendly static php urls

    I have read many articles on making friendly URLs but I can't seem to get it working properly.

    My site is hosted on a Linux box with Apache.

    All I want to do is drop the file extensions so /hello.php shows as /hello

    For the purposes of setting this up, I am working with a simple hello world file.

    [code] <?php
    Echo "Hello, World!";
    ?> [code]

    First I saved the file as "hello.php". When I navigate to mysite.com/hello.php the page appears normally.

    Next, I added the following to my .htaccess

    Code:
    <Files hello>
    ForceType application/x-httpd-php
    </Files>
    My desire is to leave my files in their current format on the server, but simply drop the extension in the URL. I couldn't find a way to do such, so I renamed the file from "hello.php" to "hello". When I navigate to mysite.com/hello I get a prompt asking if I wish to open or save the file. If I choose to open it, I see a text document with the code the same as I would if I right-clicked and chose View Page Source.

    I simply wish the file to open and display normally.

    The .htaccess file is in the same directory as the php file.

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Personally I'd just use mod_rewrite to redirect all requests for extensionless paths that don't exists to .php...

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z_-]+)$ $1.php [L]


  •  

    Posting Permissions

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