问题
Is there a way I could use htaccess' url rewriting feature to look like there's a file in let's say the /public/some/folder
when it's actually in /public
.
For example I have index.php in root folder and I want it to be like that when I access index.php then it could also behave as its in all the folders and subfolders too
When I execute index.php then it will also execute in all folders and subfolders too
Update
Please understand my question by the example below
index.php is in root and I have different folders in root as well so when I access the index.php through browser then it will also execute in other folders
http://example.com/index.php
will also behave as if its in sub folder too
http://example.com/folder1/index.php
http://example.com/folder2/index.php
http://example.com/folder3/index.php
index.php
is not in these folders but it must execute in these folders too at the same time
I think its not difficult to understand through this example.please answer accordingly
回答1:
I'm not sure that I understand you correctly. But any way you can try something like that in your .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
So after it everything will go to index.php with $_GET[page] parameter. So for example www.mydomen.com/try/to/get/this will go to our index.php where we will have our $_GET[page]="try/to/get/this". If you will use explode for this string you can write any rules you want for you url. Something like your own URL manager :)
example:
put your index.php in the root folder and also .htaccess in your index.php:
$urlArray = explode("/",$_GET['page']);
switch($urlArray[0]){
case "try":
include($_SERVER[DOCUMENT_ROOT]."/path/to/folder/what/you/need/my.php");
break;
case "another_url":
include($_SERVER[DOCUMENT_ROOT]."/another/path/to/folder/what/you/need/my_another.php");
break;
}
Hope it is what you needed.
来源:https://stackoverflow.com/questions/12050485/htaccess-rewriting-to-include-file-in-every-folder