忽略 .htaccess 中干净 URL 中的符号链接

发布于 2024-08-12 18:39:49 字数 676 浏览 2 评论 0原文

示例 URL:

example.com/user

/user 既是符号链接目录,也是我网站内容的有效 URL。我使用 Horde Routes 来请求内容,并且对该站点的所有请求都通过index.php。

我目前有一个 .htaccess 文件,如下所示:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

#allow cool urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
#allow to have Url without index.php

但是转到 /user 会列出目录内容而不是网页。是否可以忽略符号链接?

除此之外,如果您请求:

example.com/user/some-css-file.css

这是一个不应被忽略的有效请求。那么是否可以允许通过符号链接请求文件,但基本符号链接本身被忽略并转到index.php?

谢谢 :)

Example URL:

example.com/user

/user is both a symlinked directory and a valid URL to content on my site. I user Horde Routes to request the content and all requests to the site go through index.php.

I currently have a .htaccess file that looks like:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

#allow cool urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
#allow to have Url without index.php

But going to /user lists the directory contents rather than the webpage. Is it possible to ignore symlinks?

Additional to that is if you request:

example.com/user/some-css-file.css

That is a valid request that should not be ignored. So is it possible to allow files via symlinks to be requested, but the base symlinks themselves to be ignored and go to index.php?

Thanks :)

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

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

发布评论

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

评论(2

心在旅行 2024-08-19 18:39:49

当请求 /user/ 时,!-d 的测试将失败,因为它实际上是一个现有目录。您可能希望在没有该条件的情况下使用它,并且只允许直接访问现有文件而不是目录:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]

此外,您可以将模式 ^(.*) 替换为 !^index\.php$ 以便对 index.php 的请求不需要文件系统查找:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php$ index.php [L]

The test for !-d will fail when /user/ is requested since it’s actually an existing directory. You might want to use it without that condition and only allow direct access to existing files but not directories:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]

Additionally you could replace the pattern ^(.*) with !^index\.php$ so that a request for the index.php doesn’t require a filesystem lookup:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php$ index.php [L]
我ぃ本無心為│何有愛 2024-08-19 18:39:49

忘记忽略符号链接,只需创建另一个 RewriteRule。将其放在“允许酷网址”规则之前:

RewriteCond %{REQUEST_URI} ^/user/$ 
RewriteRule (.*) /index.php [L]

所以 http://www.example.com/user/< /a> 或 http://www.example.com/user 应该 转到内容。 [L] 应该阻止进一步的规则被处理。

Forget ignoring symlinks just create another RewriteRule. Place it before the "allow cool urls" rule:

RewriteCond %{REQUEST_URI} ^/user/$ 
RewriteRule (.*) /index.php [L]

So http://www.example.com/user/ or http://www.example.com/user should go to the content. The [L] should prevent further rules from being processed.

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