SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot boognish's Avatar
    Join Date
    Sep 2005
    Location
    Leeds
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove .php extention and add a slash htaccess

    Hi,

    I have a website where most files have a php extention, and want to remove the exention and add a slash using htaccess.

    So for example instead of
    http://mydomain.com/test.php

    I'd like...
    http://mydomain.com/test/

    I've tried loads of scripts from the web. They seem to work in that they remove the .php, but kept getting a 404. So I removed the .php extention from one of the files so it didn't get a 404 but the file wasn't then treated as a php file and showed the php code in the browser.

    RewriteEngine on

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\.php\ HTTP/ [NC]
    RewriteRule .+ http://www.mydomain.com/%1 [R=301,QSA]

    Can anyone tell me what I'm doing wrong?

    Thanks!

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    boog,

    Yes:

    1. You're using mod_rewrite to do your job (coding links) as webmaster, that is, you're going the wrong way! Use mod_rewrite to ADD the .php extension to extensionless URIs.

    2. By telling Apache that your links are subdirectories when they're really extensionless filenames makes everything overly complicated (and results in a directory level offset which will make your relative links worthless).

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •