【问题标题】:mod-rewrite simple redirect inside foldermod-rewrite 文件夹内的简单重定向
【发布时间】:2014-11-27 00:41:38
【问题描述】:

我在以下目录中有一个 .htaccess 文件:root/en

我的 index.php 位于以下目录中:root/en/public/index.php

如何编写 .htaccess 代码,以便当用户键入以下 URL:root/en 时,它会将他重定向到我的 index.php?

【问题讨论】:

  • 这将是默认行为,至少在启用自动索引模块时(实际上不是重定向)。
  • 对不起@clapas 我犯了一个错误你能再读一遍这个问题吗?

标签: php mod-rewrite


【解决方案1】:

您需要启用 mod_rewrite。假设 .htaccess 在根目录中,这对我有用:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/root/en/public
RewriteRule en /root/en/public [L]

在尝试之前一定要清理浏览器缓存,否则你会一直看到目录索引。

【讨论】:

  • 目前我的 .htaccess 看起来像这样:RewriteEngine on ReWriteCond %{REQUEST_URI} !en/public/ ReWriteRule ^(.*)$ public/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] 我在这里缺少什么
  • 因为我只获得了当前目录 (/en) 上的文件列表
猜你喜欢
  • 1970-01-01
  • 2011-05-06
  • 2015-09-01
  • 2012-04-18
  • 2023-04-05
  • 1970-01-01
  • 2010-11-21
  • 1970-01-01
  • 2015-08-22
相关资源
最近更新 更多