的.htaccess - 默默重写/重定向一切内部子文件夹 [英] .htaccess - silently rewrite/redirect everything to internal subfolder

查看:107
本文介绍了的.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 / 。但用户看在浏览器中的原始URL。

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天全站免登陆