重写子目录中的 URI
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)