为不同的Url重写htaccess规则

Rewrite htaccess rule for different Url

本文关键字:重写 htaccess 规则 Url      更新时间:2023-09-26

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

我试着使用这个,但它不工作

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

My present htaccess

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

和我的公共目录是真实的提前感谢

情形1:如果public是真实目录,则在/public/.htaccess:

中使用此规则
RewriteEngine On
RewriteBase /user/public/
RewriteRule ^l/(.+)$ $1 [NC,L]

Case 2:如果public不是一个真正的目录,那么在根目录.htaccess:

中使用此规则
RewriteEngine On
RewriteBase /
RewriteRule ^user/public/l/(.+)$ public/$1 [NC,L]