user3180358 user3180358 - 3 months ago 16
Apache Configuration Question

.htaccess Rewrite Issue (Change of folder and filename)

I want to redirect:

site.org/us/
site.org/us/alaska/
site.org/us/south-carolina/


to

site.org/by-state/
site.org/by-state/alaska.html
site.org/by-state/south-carolina.html


My .htaccess code:

RewriteRule ^us/*$ by-state/ [R=301,L]
RewriteRule ^us/(.*)/?$ by-state/$1.html [R=301,L]


Undesired results are as follows:

site.org/us/alaska/ is going to:
site.org/by-state/alaska/.html

site.org/us/south-carolina/ is going to:
site.org/by-state/south-carolina/.html


Please note the unnecessary trailing slash before .html.

Any help would be really appreciated.

Answer
RewriteRule ^us/*$ by-state/ [R=301,L]
RewriteRule ^us/(.*)$ by-state/$1.html [R=301,L] 
Comments