2016-03-01 72 views
1

我想改變我的web應用程序的我的文件夾結構,htaccess的重定向文件夾到其他的所有通信,包括名頭

目前的結構是

/websites 
    .subdomain1 
     .index.html 
     .app 
     .htaccess 
     index.php 

DNS: http://subdomain1.website.com/ - >指向子域的文件夾1

現在在當前結構中php位於相同的文件夾內,我想將它移出,問題是我需要將所有請求重定向到不是要重定向的文件的舊目錄,並且包括標題中的子域名。

例 當前API端點

http://subdomain1.website.com/app/token 

我想這個要求,而不是去/subdomain1/app/index.php,我希望它去/api/index.php,包括' subdomain1'作爲標題。

從而使我的文件夾結構將成爲

/website 
    .subdomain1 
    .index.html 
/api 
    index.php 

,所有車輛將重定向到新的文件夾的子域作爲頭老/ app文件夾。

當前的htaccess

Options -MultiViews -Indexes 
SetOutputFilter DEFLATE 
DirectoryIndex index.php 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule ^$ index.php [QSA,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php [QSA,L] 
</ifModule> 
+0

這是哪裏的.htaccess在什麼位置?我也沒有看到你的目錄結構中的'api'文件夾 – anubhava

+0

它的內部應用程序文件夾,我想要創建它@根目錄的api文件夾,並將所有通信重定向到它。 – Zalaboza

+1

@anubhava我編輯的問題來澄清。謝謝 – Zalaboza

回答

1

您當前的.htaccess改成這樣:

Options -MultiViews -Indexes 
SetOutputFilter DEFLATE 
DirectoryIndex index.php 

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^/api/index.php [L] 
+0

我可以包括'../'之類的盟友嗎?因爲新的index.php位於../../v1/api/index.php將工作? – Zalaboza

+0

是的,你可以在這裏使用'../'或者在目標中使用像'/ path/to/v1/api/index.php'這樣的完整路徑 – anubhava

相關問題