How to use htaccess to change image paths?

前端 未结 3 2037
没有蜡笔的小新
没有蜡笔的小新 2021-01-06 23:37

I have a html file that has an image:


Is it possible to redirect this path to another using

相关标签:
3条回答
  • 2021-01-07 00:03

    I think its easier to set a variable in your config

    <?php 
    $static_url = "http://static.example.com/";
    ?>
    <img src="<?php echo $static_url; ?>/smilies/happy.gif" alt="" />
    

    Its better then you have the control what came from static and the rewrite engine is slow when you call it everytime its not sooo good.

    0 讨论(0)
  • 2021-01-07 00:08

    RewriteRule ^(smilies/.*)$ http://static.example.com/$1 [R]

    0 讨论(0)
  • 2021-01-07 00:11

    Well, you might get away with redirecting all calls that end with /smilies/happy.gif to that directory, so it wouldn't matter where the call came from. That does mean you should not wish to call this to some other subedirectory, but I imagine you don't.

    something like this (guessing here, cann't test, so read up on the rwriting there :)

    RewriteRule     ^(.*)/images/$(.*) http://static.example.com/smilies/$2 [L,R=301]
    

    basically you are rewriting everything that has '/images/' in it to that static adress, pasting whatever was after images after the new asdress (the $2 thingy) and then indicating that this is the last command to parse (to stop strange things in the htaccess) and that you want a 301 (permanently moved) code to be sent.

    0 讨论(0)
提交回复
热议问题