In htaccess, I'd like to replace underscores with hyphens and then redirect the user the new url

后端 未结 2 429
野性不改
野性不改 2020-12-06 18:32

I\'d like to redirect any request that contains underscores to the same url, but with hyphens replacing the urls. I\'ve seen a lot of forums suggest I do something like this

相关标签:
2条回答
  • 2020-12-06 18:51

    How about combining the 2. Have a single rewrite rule that rewrites to a PHP script that does the substitution and redirect. That way you avoid having multiple rewrite rules, can handle any number of underscores and only invoke the PHP redirection when it is needed.

    0 讨论(0)
  • 2020-12-06 19:02

    See the "Next" directive/rewrite flag, which causes the ruleset to be reevaluated starting with the first rule: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_n

    Something like this might work:

    RewriteRule (.*)_(.*) $1-$2 [N] 
    
    0 讨论(0)
提交回复
热议问题