php - 使用 .htaccess 更改目录结构

标签 php apache .htaccess

我想将我所有的网站文件(甚至包括 index.php)移动到一个子目录中(对于 exp:“abc”)

例如 之前:

public_html
 index.php
 a.file
 directory
   an.other.file
 ...

之后:

public_html
 abc_directory
   index.php
   a.file
   directory
     an.other.file
   ...

我希望一切正常,就像以前一样,但我不想进行任何重定向(可见)。

人们应该输入“http://myexmaplesite.com/directory/an.other.file/”并通过 .htaccess apache 为他们提供“http://myexmaplesite.com/abc_directory/directory/an.other.file/”但没有外部重定向(301,302 等)

如何使用 mod_rewrite 将所有请求路由到子目录?

最佳答案

在您的文档根目录中尝试这个 mod_rewrite 规则:

RewriteEngine on
RewriteRule !^directory/ directory%{REQUEST_URI} [L]

或者一般来说:

RewriteEngine on
RewriteCond $1 !^directory/
RewriteRule ^/?(.*) directory/$1 [L]

这甚至应该适用于服务器或虚拟主机配置。

关于php - 使用 .htaccess 更改目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1735390/

相关文章:

php - 如何为考勤记录PHP CSS设置单选按钮?

php - 在 php 中 curl 5,000 多个 url 并将它们插入 mysql 数据库的最快方法?

apache - 在 Ubuntu 14.04 中的 apache2 上安装 SSL

PHP处理用户登录的IP封锁和泛洪控制的最佳实践

php - 如何使用 PHP 的 post 方法(Post/Redirect/Get)在表单提交后重定向

PHP 命名空间移除/映射和重写标识符

apache - 如何将我的 Web 应用程序从端口号 8080 指向 80?

php - 如何为每个目录设置 Php 的 auto_prepend_file 指令?

html - 如何在错误 404 页面短暂延迟后自动重定向?

php - 删除 php/html 扩展名并从规则中排除一个特定文件