.htaccess - 默默地将所有内容重写/重定向到内部子文件夹 [英] .htaccess - silently rewrite/redirect everything to internal subfolder

查看:23
本文介绍了.htaccess - 默默地将所有内容重写/重定向到内部子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个www.example.com 网站结构:

Let's say I have thiswww.example.com site structure:

/srv/http/
/srv/http/site/index.php
/srv/http/site/stuff.php

我希望发生以下重写/重定向:

I want the following rewrites/redirects to happen:

www.example.com/index.php -> 重定向到 -> www.example.com/site/index.php -> 但用户看到 -> www.example.com/index.php

www.example.com/index.php -> redirects to -> www.example.com/site/index.php -> but the user sees -> www.example.com/index.php

www.example.com/stuff.php -> 重定向到 -> www.example.com/site/stuff.php -> 但用户看到 -> www.example.com/stuff.php

www.example.com/stuff.php -> redirects to -> www.example.com/site/stuff.php -> but the user sees -> www.example.com/stuff.php

通常,www.example.com/ 之后的所有内容都重定向到 www.example.com/site/.但用户在浏览器中看到的是原始网址.

In general, everything after www.example.com/ redirects to www.example.com/site/. But the user sees the original URL in the browser.

我在互联网上环顾四周,但还没有弄清楚在这种特殊情况下应该使用什么.

I've looked around on the internet but haven't managed to figure out what to use in this particular situation.

我尝试重写所有内容:

RewriteEngine On
RewriteRule ^$ /site [L]

index.php 消失,www.example.com/site/ 显示给用户.

but index.php disappears and www.example.com/site/ is shown to the user.

如何使用.htaccess来解决这个问题?

How can I use .htaccess to solve this problem?

推荐答案

需要捕获传入服务器的url请求,像这样:

You need to capture the url request incoming into the server, like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule ^(.*)$ /site/$1 [L,QSA]

QSA(最终)还将查询字符串附加到重写的 url

The QSA is (eventually) to also append the query string to the rewritten url

这篇关于.htaccess - 默默地将所有内容重写/重定向到内部子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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