- This topic is empty.
-
AuthorPosts
-
May 20, 2013 at 8:40 am #44898donpeppoMember
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.May 20, 2013 at 2:47 pm #135744CrocoDillonParticipantI 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.
May 20, 2013 at 4:03 pm #135752donpeppoMembercrocodillon 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 #135756CrocoDillonParticipantThen 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.phpMay 20, 2013 at 4:56 pm #135761unasAquilaParticipanti use
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-lRewriteCond %{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 #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. : )
May 21, 2013 at 6:58 am #135814donpeppoMemberThx for the help guys. I moved the files to folders and used htaccess to “protect” them.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.