Forum Moderators: phranque
https://exmaple.com/A1B/A1B2C3/page1.html ==> https://exmaple.com/A1B/A1B2C3/page.html
https://exmaple.com/A1B/page1.html ==> https://exmaple.com/A1B/page.html
https://exmaple.com/B9R/page1.html ==> https://exmaple.com/B9R/page.html
...
rewriteRule ^[A-Za-z0-9\/\-]+\/page1\.html$ page.html
https://exmaple.com/page.html
rewriteRule ^[A-Za-z0-9\/\-]+\/page1\.html$ page.htmlYikes. The target of a RewriteRule needs to contain the full protocol-plus-hostname if it is an external redirect with R flag. (If it's an internal rewrite, start it with / for root.) So the target will be
RewriteRule ^(([\w-]+/)+)oldpage\.html https://example.com/$1newpage.html [R=301,L]
RewriteRule ^(([\w-]+/)+)page1.html$ $1page.html [R=301,L]
RewriteRule ^(([\w-]+/)+)(page)1.html$ $1$2.html [R=301,L]
https://www.example.com/A1B/A1B/2C3/page1.html
//becomes:
https://www.example.com/A1B/A1B/2C3/2C3/.html
Is there always at least one directory? If no, replace + with *.
[\w] vs [a-zA-Z0-9]
This will be an internal redirectWhat does “internal redirect” mean?
What does “internal redirect” mean?
RedirectMatch 301 "^/(([\w-]+/)+)page1\.html$" "https://www.example.com/$1page.html" You have now also learned that formatting such as [ b ] doesn’t work inside [ code ] tags ;)
I spent some time reading up on all this, mostly in Apache2 docs. To be clear my intention is to implement this in the VirtualHost context and not within an .htaccess file. As such it is not recommended to use mod_rewrite, instead I am using RedirectMatch.
The use of RewriteRule to perform this task may be appropriate if there are other RewriteRule directives in the same scope. This is because, when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file.
how are you doing hostname canonicalization?