根目录和子文件夹中的.htaccess,每个目录均重定向到自己的index.php [英] .htaccess in root and subfolder, each to redirect to own index.php

查看:78
本文介绍了根目录和子文件夹中的.htaccess,每个目录均重定向到自己的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个看似重复的问题表示歉意,但是我看过的几十个问题中都没有这个问题.

我具有以下目录结构:

/.htaccess
/index.php
/subfolder/.htaccess
/subfolder/index.php

我希望所有对页面的请求均由/index.php处理,除非该请求以/subfolder开始,在这种情况下,应由/subfolder/index.php

I'd like all requests for pages to be handled by /index.php, unless the request starts /subfolder in which case it should be handled by /subfolder/index.php

  • 例如/abc要重写为/index.php?u=abc
  • 例如/subfolder/def要重写为/subfolder/index.php?u=def
  • e.g. /abc to be rewritten to /index.php?u=abc
  • e.g. /subfolder/def to be rewritten to /subfolder/index.php?u=def

我一直在绕圈讨论,因此任何帮助将不胜感激.

忘了提问题! 子文件夹中的请求由根index.php而不是子文件夹之一处理. (对/subfolder的请求除外)

forgot to mention the problem! Requests within the subfolder are handled by the root index.php, not the subfolder one. (Except requests for /subfolder)

Options -Indexes -MultiViews +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^(.*)$ /index.php?u=$1 [NC,QSA]

/subfolder/.htaccess

RewriteBase /admin/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /admin/index.php?u=$1 [NC,QSA]

推荐答案

使您的root .htaccess像这样:

Have your root .htaccess like this:

Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!admin/)(.+)$ /index.php?u=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/(.+)$ /admin/index.php?u=$1 [NC,QSA,L]

对于此简单要求,无需在admin文件夹中具有.htaccess.

There is no need to have .htaccess in admin folder for this simple requirement.

这篇关于根目录和子文件夹中的.htaccess,每个目录均重定向到自己的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆