重写子目录中的 URI

发布于 2024-12-24 03:55:52 字数 723 浏览 0 评论 0原文

我正在使用 codeigniter 和 .htaccess 重写。目前,它将所有不存在的文件查询重写为index.php(CodeIgniter),如下所示:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]

现在,如果文件不存在,我想将以“images”开头的url重写为“application/images”。像这样的事情:

RewriteCond %{REQUEST_URI} ^/images
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./application/$1 [L]

嗯,这在根目录中有效,但在子目录中无效。 我不想将子目录名称添加到 htaccess,我希望它是动态的。因此,如果我复制该目录并重命名它,我不想将我的 htaccet 更改为该目录。

RewriteRule 是相对于我工作的目录,但 RewriteCond 不是?预先感谢:)

问题是这样解决的:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(images|js|css)(.*)$ ./application/$1$2 [L]

I'm using codeigniter and .htaccess rewriting. Currently it's rewriting all non-existing file queries to index.php(CodeIgniter), like so:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]

Now i'd like like to rewrite urls beginning with "images" to "application/images" if file doesn't exist. Something like this:

RewriteCond %{REQUEST_URI} ^/images
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./application/$1 [L]

Well, that works in root directory, but not in subdirectory.
I do not want to add subdirectory name to htaccess, i'd like it to be dynamic. So if i'll make copy of this dir, and rename it, i dont want to change my htaccet to this dir.

RewriteRule is relative to the directory im working but RewriteCond is not? Thanks in advance :)

Problem is solved by this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(images|js|css)(.*)$ ./application/$1$2 [L]

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

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

发布评论

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

评论(1

我偏爱纯白色 2024-12-31 03:55:52
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(images|js|css)(.*)$ ./application/$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(images|js|css)(.*)$ ./application/$1$2 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文