The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

mod rewrite

Discussion in 'General Discussion' started by Getox, Sep 28, 2004.

  1. Getox

    Getox BANNED

    Joined:
    Feb 4, 2004
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    this is more of an apache question but
    i want to make php work on a diff extension eg
    ".dj" will work as a php file, so what would be the .htaccess code i put in the users directory ?
     
  2. linux-image

    linux-image Well-Known Member

    Joined:
    Jun 8, 2004
    Messages:
    1,192
    Likes Received:
    1
    Trophy Points:
    38
    Location:
    India
    cPanel Access Level:
    Root Administrator
    am new ti these.. but try these:
    ========================
    You can map MIME Types to extensions, adding to or overriding the default:

    AddType image/gif fred
    AddType text/html fish

    So, any file with the extension .fred will be parsed as a gif.
    ========================

    i got it via a google.
     
  3. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    You should be able to use the following in a .htaccess file within the directory:
    Code:
    <FilesMatch "\.dj$">
        ForceType application/x-httpd-php
    </FilesMatch>
    
     
  4. myusername

    myusername Well-Known Member
    PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    691
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Any ideas on how to make a file execute as php if it has no file extension? For example:

    <Files index>
    ForceType application/x-httpd-php
    </Files>

    That works fine when php runs as a module but if it is run as a cgi (phpsuexec) it fails to work.

    Any thoughts on this?
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Have a go with this puppy. Add the following to your .htaccess instead of what you previously had:

    AddHandler application/x-httpd-php .htm .html
    AddType application/x-httpd-php .htm .html
     
  6. myusername

    myusername Well-Known Member
    PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    691
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Hi Chirpy,

    That "almost" did the trick. The file is now at least displayed in the browser, but it does not execute as php. In fact it simply prints out the raw code to the browser. I added the php shebang just for good measure but no luck there either, just raw code on the screen.
     
  7. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    You could try adding those two lines to a php.ini file in the same directory as the html files (and removing the .htaccess stuff). If that also does not work, I'm out of ideas ;)
     
  8. myusername

    myusername Well-Known Member
    PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    691
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Well thanks for the input anyways, cant seem to get it to run. I wonder if mod_rewrite would accomplish the same thing, or if it works under suexec....

    EDIT:
    Okay folks here is the fix for any of you facing similar with PHP Suexec and CMS's like contentor that use .htaccess directives like:

    Code:
    <Files index>
       ForceType application/x-httpd-php
    </Files>
    <Files edit>
       ForceType application/x-httpd-php
    </Files>
    <Files display>
       ForceType application/x-httpd-php
    </Files>
    What they are going for is trying to make search engine friendly urls. These CMS's come with files named:

    index
    edit
    display

    Just rename these to index.php edit.php display.php etc and then add this to your .htaccess file:

    Code:
    RewriteEngine On
    RewriteRule ^index(/.*)?$ index.php [L]
    RewriteRule ^edit(/.*)?$ edit.php [L]
    RewriteRule ^display(/.*)?$ display.php [L]
    This will allow the user to access their "search engine friendly" pages like:

    http://domain.com/edit without actually credit an "edit" directory and placing an index.php file in there.
     
    #8 myusername, Jan 11, 2005
    Last edited: Jan 11, 2005
Loading...

Share This Page