【问题标题】:Rewrite htaccess rule for different Url为不同的 Url 重写 htaccess 规则
【发布时间】:2015-07-28 11:49:23
【问题描述】:

我有 url public/l/img/logo.png,我想在我的公共目录中使用 htaccess 查看public/img/logo.png

我试过用这个,但它不起作用

RewriteRule ^l/(.*)$ $1 [R=301,L]

我现在的htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我的公众是真正的目录 提前致谢

【问题讨论】:

标签: javascript php regex apache .htaccess


【解决方案1】:

案例1:如果public是一个真实的目录,那么在/public/.htaccess中使用这个规则:

RewriteEngine On
RewriteBase /user/public/

RewriteRule ^l/(.+)$ $1 [NC,L]

案例 2: 如果 public 不是真实目录,则在根目录 .htaccess 中使用此规则:

RewriteEngine On
RewriteBase /

RewriteRule ^user/public/l/(.+)$ public/$1 [NC,L]

【讨论】:

  • 感谢您的帮助,但将其添加到我的 htaccess 时出现 404 错误
  • 信息不足。您使用了这两个版本中的哪一个?您在浏览器中输入了哪个完整网址
  • 我使用的是第一个版本,当我在 url 中有 l 时出现 404 错误
  • 你把那个.htaccess 放在/public/ 目录中了吗?我再说一遍你在浏览器中输入了什么完整的 URL
  • yeahm 使用了完整的 url,如 localhost/user/public/l/assets/images/spy.png 导致 404,但如果从 url 中删除“l”,它工作正常
猜你喜欢
  • 1970-01-01
  • 2011-12-06
  • 2016-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多