Welcome Guest, Not a member yet? Register   Sign In
.htaccess stuff
#1

[eluser]Fenix[/eluser]
Here is my .htaccess file. The line with the arrow disallows accessing php files via http. Is there a command I could add that would allow it for a specified controller?

So if the url was http://mysite.com/api/categories.php, could I disable this for anything after /api/ ?

Code:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
    # mod_rewrite rules
    RewriteEngine on

    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php

    # Hide all PHP files so none can be accessed by HTTP
    RewriteRule (.*)\.php$ index.php/$1                          // <------------
    
    # If the file/dir is NOT real go to index
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>
#2

[eluser]TheFuzzy0ne[/eluser]
I don't understand. What is the file you want to access via the URI?
#3

[eluser]Fenix[/eluser]
This is for a REST API where the response content-type is requested by adding .xml or .php to the endpoint like this:
http://mysite.com/api/categories.xml
http://mysite.com/api/categories.php

The first example works fine but for the .php, my htaccess file (posted above) is looking for the real file named categories.php.

So, I still want the index.php to be removed from the url
(http://mysite.com/index.php/api/categories) but I also need it to quit catching the .php extension for /api/categories.php and other api calls like /api/images.php.

If that isn't clear... my API controller has methods like categories() and images() and users(). I also have a __construct() and a _remap() function to pull in the query string throw errors if they have missed required parameters etc...

This is my _remap() for testing. The .xml extension works fine but the .php extension doesn't work.
Code:
function _remap($method)
{
    $content_type = stristr($method, '.');
    switch($content_type)
    {
        case '.php': $this->content_type = 'php'; break;
        case '.xml': $this->content_type = 'xml'; break;
        default: $this->errors[] = 1003;
    }
    echo '$this->content_type: ' . $this->content_type . '<br/>';
    echo '$content_type: ' . $content_type;
}
#4

[eluser]slowgary[/eluser]
You could just remove that line from your main htaccess. If you have other php files that you don't want accessible via http, you could keep them in a folder with another htaccess and use "deny from all".




Theme © iAndrew 2016 - Forum software by © MyBB