Forums

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
    Posts
  • #44898
    donpeppo
    Member

    Hi!
    I have a problem with my friendly urls.

    I want everything after mydomain.com/ 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: **mydomain.com/folder** becomes **mydomain.com/folder/** (adds a slash after)
    Or if you write: **mydomain.com/file.php** 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.

    #135744
    CrocoDillon
    Participant

    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 *mydomain.com/file.php* 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.

    #135752
    donpeppo
    Member

    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.

    #135756
    CrocoDillon
    Participant

    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:

    /domain
    /application
    all php except index.php
    /public_html
    index.php

    #135761
    unasAquila
    Participant

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

    #135795
    __
    Participant

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

    #135814
    donpeppo
    Member

    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.