2017-05-09 60 views
0

我想我所有的文件移動到子文件夾重定向域到一個新的子文件夾(網站和本地主機)

對於時刻:

- CssFolder1 
- ScriptFolder2 
- OtherFolder3 
- Index.php 
- File1.php 
- File2.php 
- File3.php 
- File4.php 
- File5.php 

後:

- CssFolder1 
- ScriptFolder2 
- OtherFolder3 
- FileFolder 
    - Index.php 
    - File1.php 
    - File2.php 
    - File3.php 
    - File4.php 
    - File5.php 

如何我可以將我的本地主機(和網站)重定向到子文件夾?

本地主機/ mywebsite/FileFolder/dashboard.php -----> 本地主機/ mywebsite/dashboard.php

謝謝

+1

您可以使用.htaccess文件對根對您的請求重定向到指定的目錄中的文件。 –

回答

1

將此代碼添加到您的.htaccess文件。

我假設你使用的是Apache web服務器,而不是nginx。

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_URI} !(.*)FileFolder 
RewriteRule ^(.*)$ FileFolder/$1 [L] 

如果你想使用重定向代碼你可以使用下面的代碼:

RewriteEngine On 
RewriteRule ^/FileFolder/(.*)$ http://**yourdomain**/$1 [L,R=301] 
+0

謝謝!這很好!但我可以更改錯誤消息「** Not Found 在此服務器上未找到請求的URL /mywebsite/FileFolder/file_dont_exist.php。**」? (因爲我希望用戶看不到樹) – Rocstar

+0

您可以在文件夾中添加一個空白的index.html文件,或者在您的.htaccess文件的新行中添加「Options -Indexes」。 –

+0

謝謝你的快速回復,我在FileFolder添加的index.html(空白),和我的htaccess的樣子'選項-Indexes 選項+的FollowSymLinks RewriteEngine敘述 上 的RewriteCond%{REQUEST_URI}!(。*)FileFolder 重寫規則^(。*)$ FileFolder/$ 1 [L]'但我有相同的頁面(找不到頁面...) – Rocstar

相關問題