Php 将域重定向到新的子文件夹(网站和本地主机)

Php 将域重定向到新的子文件夹(网站和本地主机),php,.htaccess,redirect,Php,.htaccess,Redirect,我想将所有文件移动到子文件夹中 目前: - 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

我想将所有文件移动到子文件夹中

目前:

- 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
如何将本地主机和网站重定向到子文件夹

localhost/mywebsite/FileFolder/dashboard.php--> localhost/mywebsite/dashboard.php


谢谢

将此代码添加到.htaccess文件中

我假设您使用的是apacheweb服务器,而不是nginx

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)FileFolder
RewriteRule ^(.*)$ FileFolder/$1 [L]
如果要使用重定向代码,可以使用以下代码:

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

您可以使用根目录下的.htaccess文件将请求重定向到指定目录下的文件。谢谢!这工作很棒!但是我可以更改错误消息Not Found请求的URL/mywebsite/FileFolder/file_dont_exist.php在此服务器上找不到?因为我希望用户看不到树,所以您可以在文件夹中添加一个空白index.html文件,或者在.htaccess文件的新行中添加选项-索引。感谢您的快速回复,我在FileFolder中添加index.html blank,我的htaccess看起来像是Options-index Options+FollowSymLinks RewriteEngine on RewriteCond%{REQUEST_URI}*FileFolder RewriteRule^.*$FileFolder/$1[L]但我没有找到相同的页面。。。