.htaccess :将任何链接转发到 /index.htm

发布于 2024-08-28 13:40:23 字数 520 浏览 2 评论 0原文

我想执行以下操作:

如果用户访问某个网址或输入该网址,并且它符合以下任何内容:

  • /path/path/path
  • /path
  • /path/path/

我希望 htaccess在触发 404 之前将它们转发到该 url + /index.htm。另外,我想忽略某些路径的此规则。这是我正在尝试但没有成功的方法:

RewriteCond %{REQUEST_URI} !^(admin)
RewriteCond %{REQUEST_URI} !^(node)
RewriteRule ^/(.*)/$ $1/index.htm [L]

这是该应用程序的概述。它实际上是应用程序内的一个子目录,因为该站点目前正在过渡。

ParentApp/
  /folder/
  /folder/
  /Drupal/
    /(new application here)
    /...
    /...

I'd like to do the following:

If a user gets to a url or types it in, and it is along the lines of any the following:

  • /path/path/path
  • /path
  • /path/path/

I would like htaccess to forward them to that url + /index.htm before triggering a 404. Also, I would like to ignore this rule for certain paths. Here is what I was trying and wasn't having success:

RewriteCond %{REQUEST_URI} !^(admin)
RewriteCond %{REQUEST_URI} !^(node)
RewriteRule ^/(.*)/$ $1/index.htm [L]

Here is how the app is outlined. It is actually a subdirectory within an application as the site is in transition at the moment.

ParentApp/
  /folder/
  /folder/
  /Drupal/
    /(new application here)
    /...
    /...

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

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

发布评论

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

评论(2

A君 2024-09-04 13:40:23

您重写的方式看起来就像您只是试图将“index.htm”显示为每个目录的索引文件,实际上您并没有重定向到任何地方。这可以使用DirectoryIndex index.htm轻松模仿。

如果您尝试重定向到根索引文件,这里有一个更简单的方法:

RewriteRule !^(admin/(.*)|node/(.*)) index.htm [L]

这是类似于我在我的网站上使用的规则。确保您已打开RewriteEngine

The way you're rewriting looks like you're just trying to have 'index.htm' display as your index file for every directory, you're not actually redirecting anywhere. This can easily be imitated using DirectoryIndex index.htm.

If you trying to redirect to the root index file, here's an easier way to do it:

RewriteRule !^(admin/(.*)|node/(.*)) index.htm [L]

This is a rule similar to what I use for my website. Make sure you have RewriteEngine On.

东北女汉子 2024-09-04 13:40:23

解决了。使用了错误的正则表达式字符。现在可以工作了。

Solved it. Was using the wrong regex character. Works now.

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