Search code examples
apache.htaccesshttp-redirecthttp-status-code-301

301 redirect from url with suffix to url without suffix


How would I redirect:
http://www.mydomain.com/dynamicname_fixedsuffix.someimageextension
To:
http://www.mydomain.com/dynamicname.someimageextension
?

Thank you!


Solution

  • I think this would do:

    RewriteRule ^(.*)_fixedsuffix(.*)$ /$1$2 [R=301,L]
    

    $1 is whatever comes before the _fixedsuffix, and $2 is whatever comes after.

    You might want to use something like http://htaccess.madewithlove.be/ to test your rules.

    And there is also a whole lot of articles and resources on line explaining those concepts.