apache mod 重写
请需要一些重写方面的帮助。
我有域名 http://www.example.com
。根目录下有多个文件夹。我想将 http://www.example.com/folder1/public/index.php
重写为 http://www.example.com/folder1
我无法访问主 apache 配置,因此我需要在 .htaccess
中执行此操作。如果可能的话,我还想将 .htaccess
放在 folder1
中,而不是放在根目录中。
任何帮助都会很棒,谢谢。
Need some help with a rewrite please.
I have domain http://www.example.com
. There are multiple folders within the root. I'd like to rewrite http://www.example.com/folder1/public/index.php
to http://www.example.com/folder1
I dont have access to the main apache config so i'll need to do this in a .htaccess
. If possible I'd also like to place the .htaccess
inside folder1
, not in the root.
Any help would be awesome, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
思考猴子很接近。尝试:
您需要
RewriteBase
并且需要停止规则的递归计算。(?!public/)
位仅表示不匹配任何已以public/
开头的内容。您在 .htaccess 规则中需要这种保护。Thinking monkey is close. Try:
You need the
RewriteBase
and you need to stop recursive evaluation of the rule. The(?!public/)
bit just means don't match anything already starting withpublic/
. You need this sort of guard in .htaccess rules.我假设您正在尝试将任何对
folder1
的请求重定向到folder1/public
。我的意思是,您希望 URL 看起来像
http://www.example.com/folder1
而实际 URL 是http://www.example.com/folder1 /public/index.php
。首先,您必须在 href 中使用
http://www.example.com/folder1
并将其重写为http://www.example.com/folder1/public/索引.php
。将以下内容添加到文件夹
folder1
中的.htaccess
中。I presume you are trying to redirect any request to
folder1
tofolder1/public
.By that I mean, you want your URLs to look like
http://www.example.com/folder1
while the actual URL will behttp://www.example.com/folder1/public/index.php
.First of all, you have to use
http://www.example.com/folder1
in your hrefs and rewrite this tohttp://www.example.com/folder1/public/index.php
.Add the below to your
.htaccess
residing in your folderfolder1
.