Forum Moderators: phranque

Message Too Old, No Replies

Redirect and rewrite URLS

         

youfoundjake

5:48 pm on Oct 23, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Morning all,
I got a site with static pages, example.com/new-york-city.html that is being moved to a new address and new structure with wordpress. new-example.com/directory/nyc
I'm looking at 301 to redirect the old site, but there are about 100 pages that need to redirect to the corresponding page on the new site.
Is there a mask that can be used or will I have to create a custom redirect for each page?

Thanks all

lucy24

6:01 pm on Oct 23, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a mask that can be used or will I have to create a custom redirect for each page?
SInce you haven't told us anything about either the old or the new URL structure, this question cannot be answered.

If it is your own server (not shared hosting) you can do it with a RewriteMap. Or, if the old URLs are readily distinguishable from new URLs (a final .html is a good indicator), you could rewrite to a PHP script that looks up old and new and issues the redirect.

In some circumstances it may be possible to do it internally within WordPress, but at some cost in server resources.

youfoundjake

6:46 pm on Oct 23, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the old structure is www.example.com/new-york-city.html
the new structure is www.new-example.com/directory/nyc

The old structure has .html at the end of the URI, where as the new structure is extensionless since it's running wordpress.

phranque

8:38 pm on Oct 23, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i would internally rewrite any requests ending in .html to a script that 301 redirects to the new url for valid requests and returns a 404/410 as appropriate for non-valid requests.

this rewrite should appear early in the mod_rewrite rulesets to avoid chained redirects.

lucy24

10:16 pm on Oct 23, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



this rewrite should appear early in the mod_rewrite rulesets to avoid chained redirects.
In particular, it must appear before the WordPress envelope, or chaos will ensue.

Ordinarily I recommend grouping RewriteRules by flag (F, G, R, L). But here it’s a case of function overriding form. Since the end result of the rewrite is to create a redirect--even though server logs will only ever show a 200--the rule needs to be grouped with other specific external redirects, before the general ones like hostname canonicalization.

Sure, it is possible to write a hundred individual redirects and place them one after another in htaccess. But oh, what a mess.