samedi 25 avril 2015

Relative path to sub-directory in PHP and Apache's htaccess file


I am working on my own PHP Framework. I am currently developing it on localhost and everything related to project is in subfolder called RuddyPhpFramework, so the path look like this:

localhost/RuddyPhpFramework/

In that folder, I do have index.php, the init point of whole Framework. I am currently working on my own router, but I have a two problems. First, in Apache's htaccess file a have this:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) RuddyPhpFramework/index.php [L]

So whenever someone acces a page like this:

localhost/RuddyPhpFramework/something/smtelse/

The index.php will init the application and echo a path for me, which is:

[path] => /RuddyPhpFramework/something/smtelse/

But that is not excatly what I want. What I want is to get a relative path to subfolder (I don't know if I am explaining this correctly), for example:

[path] => /something/smtelse/

And another problem is that I want to setup the htacces so the last line would look something like this:

RewriteRule (.*) index.php [L]

So it will go for the index.php in the folder where is the htaccess file (/RuddyPhpFramework/index.php) and not /index.php, without specifying the foler, because if someone else will be using the framework, he might have it in a folder with different name.


Aucun commentaire:

Enregistrer un commentaire