htaccess 仅在根文件夹中

发布于 2024-12-26 07:57:09 字数 155 浏览 1 评论 0原文

我一直在寻找答案,但没有找到。我在根文件中有 .htaccess,它将 /loremipsum/ 重定向到 index.php?url=loremipsum,但是,它也想在子目录中工作。我有很多这样的文件,因此将 .htaccess 文件放入每个人中会很痛苦。有什么办法让它只在根文件夹中工作吗?

I was looking for an answer, but didn't find it. I have .htaccess in root file which redirect /loremipsum/ to index.php?url=loremipsum, but, it also wants to work in subdirectories. I have a lot of them, so putting .htaccess file in everyone would be painful. Is there any way to make it working only in root folder?

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

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

发布评论

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

评论(2

你爱我像她 2025-01-02 07:57:09

如果添加此规则,它将仅适用于不存在的文件和文件夹

Options -MultiViews +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?url=$1 [L]

if you add this rules it will only work on files and folders that didnt exist

Options -MultiViews +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?url=$1 [L]
顾铮苏瑾 2025-01-02 07:57:09

要使您的重定向规则仅在根目录中工作,请使用以下基于否定lokahead的代码:

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]*)(?!/.*)$ index.php?url=$1 [L]

To make your redirect rule work only in root dir use this negative lokahead based code:

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

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