【问题标题】:Rewrite root directory to subdirectory将根目录改写为子目录
【发布时间】:2017-05-13 03:19:13
【问题描述】:

我正在开发一个网站,该网站在两个不同的目录中运行一个后端和一个前端。

  • /前端/
  • /admin/

我想将 /frontend/ 作为根目录运行,同时仍将 /admin/ 作为它自己的目录运行。

我需要在 .htaccess 中写入什么来执行此操作。

这是我的 .htaccess 文件目前的样子:

# Set the default handler.
DirectoryIndex index.php

# Prevent directory listing
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    ErrorDocument 404 /admin/404.php
</IfModule>

我们将不胜感激。

【问题讨论】:

标签: php apache .htaccess mod-rewrite content-management-system


【解决方案1】:

在RewriteEngine On之后添加这个:

# Redirect any requests within frontend/, removing frontend/
RewriteRule ^frontend/(.*)$ http://www.example.com/$1 [R=301,L]
# Rewrite anything that is not in admin/ to frontend/
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^(.*)$ frontend/$1 [L]

请务必在第 2 行更新基本网站 URL。

【讨论】:

  • 由于某种原因,我在根目录收到一个错误 403 禁止错误。
  • 听起来您的frontenddirectory 中没有可提供的索引文件,如果您关闭了自动索引,则会给出 403。 frontend 中是否有 index.php 文件?既然您将 DirectoryIndex 更改为只接受它,它只会适用于此。
  • 对不起,我犯了两个错误。请使用新规则对其进行更新。在第二行和最后一行将+ 更改为*。
  • 禁止错误现已消失 - 太好了!但是我仍然收到“192.168.33.10 重定向你太多次”的任何想法?
  • 我在最后一条规则中添加了L 标志,希望可以阻止这种情况。否则尝试将其更改为[END]。
猜你喜欢
  • 2011-08-24
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 2012-01-26
  • 2014-10-24
  • 2013-10-02
相关资源
最近更新 更多