The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End .htaccess friendly url

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #44898

    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.


    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.


    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.


    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


    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 `.


    > 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. : )


    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)
  • The forum ‘Back End’ is closed to new topics and replies.