.htaccess 和 url 重写挑战
我的问题很简单。
我的根目录中有几个文件夹:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要内部重写,因此将
/
重写为/folder1/
就足够了you need internal rewrite, So it's enough to rewrite
/
to/folder1/
您将使用两个 .htaccess 文件来解决此问题。这是您放入其中的内容以及它们的去向。
文件#1。这将进入您的基本文件夹(包含 [folder1]、[folder2] 等的文件夹)
文件 #2。这位于 [folder1] 中
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)
File #2. This goes in [folder1]
尝试这样的事情
Try something like this