.htaccess RewriteRule Tip – Place Sub-page Rewrites Above Top Level Rewrites

For example, when rewriting a URL, place top level redirects below sub page redirects.

Like this:

RewriteRule ^example-page/redirected-url example/sub-page [R=301,L] RewriteRule ^example-page/another-redirected-url example/another-sub-page [R=301,L] RewriteRule ^example-page example [R=301,L]

Not this:

RewriteRule ^example-page example [R=301,L] RewriteRule ^example-page/redirected-url example/sub-page [R=301,L] RewriteRule ^example-page/another-redirected-url example/another-sub-page [R=301,L]

For me, placing the top level redirect above the specific pages just redirected all pages to ‘example’.

Leave a Reply

Your email address will not be published. Required fields are marked *