apache mod 重写

发布于 2025-01-03 08:27:07 字数 348 浏览 1 评论 0原文

请需要一些重写方面的帮助。

我有域名 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 技术交流群。

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

发布评论

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

评论(2

你的呼吸 2025-01-10 08:27:07

思考猴子很接近。尝试:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /folder1

RewriteRule ^(?!public/)(.*) public/$1 [L]

您需要RewriteBase并且需要停止规则的递归计算。 (?!public/) 位仅表示不匹配任何已以 public/ 开头的内容。您在 .htaccess 规则中需要这种保护。

Thinking monkey is close. Try:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /folder1

RewriteRule ^(?!public/)(.*) public/$1 [L]

You need the RewriteBaseand you need to stop recursive evaluation of the rule. The (?!public/) bit just means don't match anything already starting with public/. You need this sort of guard in .htaccess rules.

呆° 2025-01-10 08:27:07

我假设您正在尝试将任何对 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 中。

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

I presume you are trying to redirect any request to folder1 to folder1/public.
By that I mean, you want your URLs to look like http://www.example.com/folder1 while the actual URL will be http://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 to http://www.example.com/folder1/public/index.php.

Add the below to your .htaccess residing in your folder folder1.

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