Results 1 to 2 of 2

Thread: removing .php through htaccess file

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question removing .php through htaccess file

    hi all,
    my site is on root, i have to remove .php extension for all the url in my website,please help.

    thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I've moved this thread to the "Other" forum (for .htaccess; PHP might be ok too). It's not a Javascript question. Please post in the right area.


    There are several ways to do this, some easier and some harder (better also):

    1. You can just use index pages, index.php, and link to the folder:
    example.com/something/index.php
    Just link to:
    example.com/something/
    (You could even force redirects using .htaccess or another method if the /index.php page is requested directly.)
    That will only work for index pages, though, not for something like /other.php

    2. If you are worried about the 'security' of showing '.php' you can use .htm as the extension on the pages and then set (in .htaccess or other server configurations) '.htm' as a PHP-parsed extension (find where .php is parsed as PHP and just add a line for .htm). This will work fine and some people do it. The problem is that this will parse every .htm file as php, so it will slow the processing of non-php pages (if there are any) and also might be a security issue if you forget about some php code in an htm page or you allow users to upload .htm files-- basically at that point .htm IS .php, so it has the same security issues.

    3. You can use mod_rewrite, an apache module, through .htaccess. (It's installed on most versions of apache).
    This is the best/most complete solution, but it can get VERY difficult.
    Basically it's a way to take the request URL and change it and serve the changed URL-- but STILL show the original request URL.
    Basically, you ask for 1.php and the server gives you 2.php or anything else you want.
    Look at some tutorials. It's confusing and requires an understanding of regular expressions ('regex'), a symbolic way to match variable strings (such as 'any string including both numbers and letters', but it gets more complex than that and it's all in code/shorthand).

    If you are fairly good with PHP, then here's an easy way around it, so that you can use PHP to do the redirect instead of .htaccess. It USES .htaccess, but the code is explained in the thread. Once you set this up, you will make a PHP page that effectively serves any page you want.
    http://www.dynamicdrive.com/forums/s...ad.php?t=51923
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •