.htaccess重写规则,如果是特定文件夹

发布于 2025-01-21 07:31:55 字数 435 浏览 2 评论 0原文

我需要对.htaccess文件进行一些帮助,专门使用重写规则

我的目录结构:

root
├── plans
│   │── .htaccess
│   │── app 
│   └── public
└── Wordpress

结果我想要的结果:

如果用户转到目录https:// localhost:8888/plans/plans/ HTACCESS文件将其重写为子文件夹 public (https:// localhost:8888/plans/public),

我到目前为止尝试过的是,

RewriteEngine On

RewriteRule ^$ /public/ [L]

这给了我的404错误。

这是可能的,我该怎么做?

I need some help with my .htaccess file specifically with a rewrite rule

My directory structure:

root
├── plans
│   │── .htaccess
│   │── app 
│   └── public
└── Wordpress

The result what I want:

If the user goes to the directory https://localhost:8888/plans/
The htaccess file rewrite this to the subfolder public (https://localhost:8888/plans/public)

What I tried so far

RewriteEngine On

RewriteRule ^$ /public/ [L]

This gives my a 404 error not found.

Is this possible and how can I do this?

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

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

发布评论

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

评论(1

埋情葬爱 2025-01-28 07:31:55

您可以在plan/.htaccess中使用此规则:

RewriteEngine On

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

这将在/plans/中将所有路径重写为/plans/plubly/public/(?!public/)如果URI已经是/plans/public/public/,可以停止重写的负面lookahead。

You may use this rule in plans/.htaccess:

RewriteEngine On

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

This will rewrite all paths in /plans/ to /plans/public/. (?!public/) is a negative lookahead to stop rewrite if URI is already /plans/public/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文