【问题标题】:RewriteRule for images图像的重写规则
【发布时间】:2016-01-27 00:43:51
【问题描述】:

我必须在我的网站上重写一些网址。我把它放在我的 htaccess 中以进行此更改: http://example.com/john/?a=1&b=2 --> http://example.com/index.php?account=john&a=1&b=2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ ./index.php?account=$1 [NC,QSA,L]

现在我必须以这种方式重写图像 url。具有此路径的每张图片:example.com/john/images/a.jpg

应该指向物理路径:example.com/accounts/john/images/a.jpg

我该怎么做?

注意:“John”不是固定的,而是所有可能的词。

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    你可以试试这个脚本:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ /index.php?account=$1 [NC,QSA,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/images/([^/]+).jpg$ /accounts/$1/images/$2.jpg [NC,L]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多