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

permanent redirect of url's with .html and w/o .html


I am doing some permanent url redirects through .htaccess

I am using the following code:

Redirect permanent /someurl.html http://thedomain.com/newurl.html

I would like the redirect to apply to url s that end with .html and that end with non .html

example

Redirect permanent /someurl.html http://thedomain.com/newurl.html
Redirect permanent /someurl http://thedomain.com/newurl.html

How could achieve this without the two lines (is there a way to abbreviate)?

Thank you,


Solution

  • I'm not sure if you can use regexs in Redirect statements but if you can this should work:

    Redirect permanent /someurl(.html)? http://thedomain.com/newurl$1
    

    If you can't, a RewriteRule like this should work instead:

    RewriteRule ^someurl(.html)?$ http://thedomain.com/newurl$1 [L,R=301]