Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

php - htaccess rewriting to include file in every folder

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...