Give help. Get help.

  • # May 20, 2013 at 8:40 am

    I have a problem with my friendly urls.

    I want everything after should be handled as ?page=

    This is how far I’ve got so far in my .htaccess

    DirectoryIndex index.php
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]*)(.*) index.php?page=$1 [NC,L]

    And it works pretty well if write /login my pagehandler catch it as **?page=login**
    but if you write an existing filename it doesn’t work.
    Example: **** becomes **** (adds a slash after)
    Or if you write: **** it loads that php file but i want it not to.
    I want it to be handled as **?page=file.php**

    And i guess this may lead to problems linking to css, and js, if it does and you have any suggestions on how to solve that as well
    i would be very thankfull.

    I hope I’m not to confusing for you guys.
    and thanks in advance for any help you can provide.

    # May 20, 2013 at 2:47 pm

    I think you can remove the line with -d since you probably don’t want users to browse directories like that anyway. About existing files… why would you want ** rewritten as *?page=file.php*? Isn’t the whole point of pretty URLS not having to use file names? You can put your php files except index.php in a private folder, so people can’t navigate to those directly.

    # May 20, 2013 at 4:03 pm

    crocodillon thats the point. i dont it want to detect files and folders. i have a class that handles the $_get variable but if i write file.php it loads that file and never gets handled by my class.

    # May 20, 2013 at 4:41 pm

    Then don’t have file.php publicly available. If your server allows you to put php files (and include them from within index.php etc.) outside the public html folder, I’d do that. If not you can use .htaccess to make a hidden directory.

    Something like:

    all php except index.php

    # May 20, 2013 at 4:56 pm

    i use

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]

    and have never had problems

    but `RewriteCond %{REQUEST_FILENAME} !-f` is doing exactly what it is supposed to do if the file dose not exist then rewrite to `index.php` if you want everything to point to `index.php` then remove `RewriteCond %{REQUEST_FILENAME} !-f` and `RewriteCond %{REQUEST_FILENAME} !-d `.

    # May 20, 2013 at 9:29 pm

    > Then stop telling it to. I wouldn’t recommend it, though – there may come a time when you do want files to be accessed directly.

    For example, when you start serving scripts, stylesheets, and images. : )

    # May 21, 2013 at 6:58 am

    Thx for the help guys. I moved the files to folders and used htaccess to “protect” them.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.