Welcome to WebmasterWorld Guest from 3.81.29.226

Forum Moderators: Ocean10000 & phranque

Redirect and rewrite URLS

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

Senior Member

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

joined:Apr 28, 2006
posts:1046
votes: 3


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
6:01 pm on Oct 23, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15934
votes: 887


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.
6:46 pm on Oct 23, 2019 (gmt 0)

Senior Member

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

joined:Apr 28, 2006
posts:1046
votes: 3


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.
8:38 pm on Oct 23, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11870
votes: 244


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.
10:16 pm on Oct 23, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15934
votes: 887


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.