douzhang6646 2015-08-08 20:03
浏览 57
已采纳

使用htaccess更改带参数的URL

Like on the title, I'm looking for a way to change a url with parameters (from this www.animevid.net/player/?anime=d/dmc to this www.animevid.net/player/anime/d/dmc) using the .htaccess file.

I've found many similar post but I've only got errors, loop redirect, or...nothing. The nearest thing i've got is this code :

RewriteRule ^player/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) player/index.html?anime=$1&t=$2 [NC,L]

Also please note the "d/dmc" on "?anime=d/dmc", is a variable, another example is "c/codegeass", "s/sao" etc...

  • 写回答

1条回答 默认 最新

  • dor65412 2015-08-08 20:33
    关注

    As mentioned above the final, rewritten url you give as an example is invalid. You should escape the last /:

    https://www.animevid.net/player/anime/d%2Fdmc
    

    and rewrite to:

    https://www.animevid.net/player/?anime=d%2Fdmc
    

    Then you have to change your regex strategy for this to work. Try something like that:

    RewriteEngine On
    RewriteRule ^player/([^/]+)/([^/]+) player/index.html?anime=$1&t=$2 [NC,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?