2017-05-09 90 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

相关问题