mod_rewrite - 添加 REQUEST_FILENAME 变量的路径

发布于 2024-12-11 18:47:03 字数 1143 浏览 0 评论 0原文

这是我的代码:

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

我想表达:

  • 如果文件 {REQUEST_FILENAME} 不存在 AND if file application/public/%{REQUEST_FILENAME} 存在进行重写

示例结果:

  • /style.css = /application/public/style.css
  • /gfx/logo.png = /application/public/gfx/logo.png
  • /index.php = /index.php
  • /Welcome = /index.php?input=Welcome (它正在工作)

这个表达式的正确代码是什么?我想我需要换行:

RewriteCond application/public/%{REQUEST_FILENAME} -f 

但我不知道如何...

完整的 .htaccess 列表:

RewriteEngine on

RewriteRule style,(.+).css tmp/merged/css,$1 [L,QSA]
RewriteRule script,(.+).js tmp/merged/js,$1 [L,QSA]

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

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php?input=$1 [L,QSA]

(对不起我的英语)

Here is my code:

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

I want to make expression:

  • If file {REQUEST_FILENAME} doesn't exist AND if file application/public/%{REQUEST_FILENAME} exists do rewrite

Example results:

  • /style.css = /application/public/style.css
  • /gfx/logo.png = /application/public/gfx/logo.png
  • /index.php = /index.php
  • /Welcome = /index.php?input=Welcome (it's working)

What is proper code for this expression? I think i need to change line:

RewriteCond application/public/%{REQUEST_FILENAME} -f 

But i have no bloody idea how...

Full .htaccess listing:

RewriteEngine on

RewriteRule style,(.+).css tmp/merged/css,$1 [L,QSA]
RewriteRule script,(.+).js tmp/merged/js,$1 [L,QSA]

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

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php?input=$1 [L,QSA]

(sorry for my english)

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

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

发布评论

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

评论(1

人间☆小暴躁 2024-12-18 18:47:03

我找到了一个小解决方法,但这不是优雅的解决方案:(

RewriteEngine on

# Access to files in ./application/public
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) application/public/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule application/public/(.*) $1 [DPI]

# Main rewrite
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php?input=$1 [L,QSA,DPI] 

i've found small workaround, but it's not elegant solution :(

RewriteEngine on

# Access to files in ./application/public
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) application/public/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule application/public/(.*) $1 [DPI]

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