Results 1 to 4 of 4

Thread: .htaccess

  1. #1
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default .htaccess

    Hi

    Ive never really needed much to do with the .htaccess file and I dont know a great deal about it. However, I have built part of my site with allowance for friendly URL's. I use the method where by I drop the .php extension and use the '/' (forward slashes) as a separator in an array. Anyway, it worked localy with my apache server setup but when I uploaded my site to my host I found that the search page just shows all of my php instead of executing it. It also pends me to download my "search" file.

    .htaccess file includes;
    Code:
    AddType x-mapp-php5 .php
    
    <Files search>  
     ForceType application/x-httpd-php  
    </Files>
    The first file was specified to be included if I wanted to use php5 instead of the default version 4. Ive tried with and without this line so I know it to be causing no problems.

    The .htaccess file is contained in my root and the search file is within the same directory.

    Anyone know what could be the problem?
    Thanks
    Dal
    Programmers are tools used to convert Caffeine to code

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    You have the type added but no handler. The basic one is as such:

    Code:
    AddType application/x-httpd-php5 .html .htm .php
    AddHandler application/x-httpd-php5 .html .php .htm
    Also, if you are just after friendly URLs, follow the examples here taken from B&T's Tips and Scripts site:

    Quote Originally Posted by tips-scripts.com
    If you want your website to have friendly URLs you can use this .htaccess code. With this example code, the URL http://example.com/about would cause the page about.htm to load.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.
    RewriteCond %{REQUEST_FILENAME}\.htm -f
    RewriteRule ^(.*)$ $1.htm [L]

    With the above example, if there is no dot in the requested name (this prevents executing the filename lookup logic for every file request), and the request matches a filename (with a .htm on the end), it will take the request and put .htm on the end.

    There are two restrictions with this method. Make sure there is not a directory with the same name as the url you are using (if using http://example.com/about - make sure there is not a directory named about), or you may get undesired results. And the page you wish to load cannot have a dot in the name (i.e. about.me.htm will not work).

    Here is a second method. This one does not do a filename check so it is faster, but it could also do a rewrite when there is no file.

    RewriteEngine On
    RewriteRule ^([^\./]+)$ $1.htm [L]

    With the above example, if there is no dot or slash in the requested name, and the request is not empty (meaning the default page), it will take the request and put .htm on the end.

    There are also two restrictions with this method. Make sure there is not a directory with the same name as the url you are using (if using http://example.com/about - make sure there is not a directory named about), or you may get undesired results. And the page you wish to load cannot have a dot or slash in the name (i.e. about.me.htm or sub/about.htm will not work).

    You can make any number of variations as to the criteria using these examples as a starting point.
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. The Following User Says Thank You to BLiZZaRD For This Useful Post:

    Dal (09-01-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Thanks BLiZZaRD

    Im not too clued up on .htaccess as you may realise and I currently have a working script to take the url path and split it using the "/" forward slashes. The code I created works great (that wasnt me on my high horse, I mean that it just works well).

    Im not sure how much control I have with my current host and I will certainly look into handling things differently when (or if) I get a dedicated server. Because Im a noob on servers and I love linux for its stability and its functionality (also because it's not M$) but I need a place to start with learning the foundation. I know this is now getting off topic but linux apache web foundation tutorials would be great if you or anyone else knows of any sites that would provide everything I need to know (at a beginner level)?

    Thanks for the help.

    ps my host eventually responded and they have suggested I use;

    AddType x-mapp-php5 .php

    <Files search>
    ForceType x-mapp-php5
    </Files>
    <Files viewbizybox>
    ForceType x-mapp-php5
    </Files>

    Would that be the same as what you suggested?
    Programmers are tools used to convert Caffeine to code

  5. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    A great resource for .htaccess (and many other things) is B&T's Scripts

    And of course, you can always go right to the source

    What you have will work, but with that method you MUST end your files in a .php5 extension, instead of just .php
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •