.htaccess 和 url 重写挑战

发布于 2024-12-07 05:49:01 字数 1102 浏览 3 评论 0原文

我的问题很简单。

我的根目录中有几个文件夹:

[folder1]
[folder2]
[folder3]

我的域名类似于:http://johndoe.net

我将我的网站保存在 [folder1] 中,所以基本上我可以访问它通过输入 http://johndoe.net/folder1

我的目标是这样的:

我想输入 http://johndoe.net 我得到的内容http://johndoe.net/folder1 但地址必须保留 http://johndoe.net

我想输入 http://johndoe.net /folder1 并查看我的网站,但我的地址必须更改为 http://johndoe.net

看起来很简单,但经过几个小时的搜索后我未能找到解决方案。

到目前为止,我实现的唯一一件事就是通过将这段代码放在我的文件中,从 http://johndoe.net 重定向到 http://johndoe.net/folder1 .htaccess 在我的根目录中:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "http\:\/\/johndoe\.net\/folder1\/" [R=301,L]

当我输入 http://johndoe.net 时,我会得到 http://johndoe.net/folder1我的地址栏

,但我需要的是我的地址仍然http://johndoe.net

有人可以帮助我吗?

My problem is very simple.

I have several folders in my root:

[folder1]
[folder2]
[folder3]

And my domain is something like: http://johndoe.net

I keep my website in [folder1], so basically I access it by typing http://johndoe.net/folder1

My goal is this:

I want to type http://johndoe.net and I get the content of http://johndoe.net/folder1 but the address has to remain http://johndoe.net

I want to type http://johndoe.net/folder1 and see my website, but my address has to change to http://johndoe.net

Seems easy enough, but I failed finding the solution after several hours of searching.

So far, the only thing I achieved is redirecting from http://johndoe.net to http://johndoe.net/folder1 by placing this bit of code in my .htaccess in my root:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "http\:\/\/johndoe\.net\/folder1\/" [R=301,L]

When I type http://johndoe.net, I get http://johndoe.net/folder1 in my address bar

but what I need is my address to remain http://johndoe.net

Could anyone help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞄了个咪的 2024-12-14 05:49:02
RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "\/folder1\/" [L]

您需要内部重写,因此将 / 重写为 /folder1/ 就足够了

RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "\/folder1\/" [L]

you need internal rewrite, So it's enough to rewrite / to /folder1/

绿萝 2024-12-14 05:49:01

您将使用两个 .htaccess 文件来解决此问题。这是您放入其中的内容以及它们的去向。

文件#1。这将进入您的基本文件夹(包含 [folder1]、[folder2] 等的文件夹)

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^((www\.)?johndoe.net)$ 
RewriteRule ^(.*)$ /folder1/$1 [L]

文件 #2。这位于 [folder1] 中

RewriteEngine Off

You're going to use two .htaccess files to solve this problem. Here's what you put in them, and where they go.

File #1. This goes in your base folder (the one that contains [folder1],[folder2], etc)

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^((www\.)?johndoe.net)$ 
RewriteRule ^(.*)$ /folder1/$1 [L]

File #2. This goes in [folder1]

RewriteEngine Off
春夜浅 2024-12-14 05:49:01

尝试这样的事情

RewriteRule ^(.*)$ /folder1/$1 [R=301,L]

Try something like this

RewriteRule ^(.*)$ /folder1/$1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文