rewrite url using mod rewrite without redirection

前端 未结 1 1400
夕颜
夕颜 2020-12-16 21:42

this url is being rewritten

http://domain.com/embed/slideshow-image-list.js

to this

http://domain.com/code/embed/slideshow         


        
相关标签:
1条回答
  • 2020-12-16 22:03

    Don't supply the domain in the rule, just the path. With the full domain it will be redirected.

    RewriteRule ^embed/([^\.]+)\.js$ /code/embed/$1 [L]

    Alternately, if the resulting path is not a real file and should be handled by index.php, stip off the [L] so that the next rule will be executed:

    RewriteRule ^embed/([^\.]+)\.js$ /code/embed/$1

    Note that the mod_rewrite guide says the following, which would seem to indicate that the full URL path is okay, but I believe it compares against ServerName, not necessarily ServerAlias (I'm not 100% sure about that, but I've always used paths rather than full URLs in doing non-redirect rewrites):

    Absolute URL

    If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.

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