URL rewriting

60 views
Skip to first unread message

Mark Orciuch

unread,
Apr 29, 2021, 11:35:46 AM4/29/21
to dotCMS User Group
Hello,

I am wondering if something like this is possible. I have some legacy urls coming from Google searches that need redirection. For example:

/portal/group/auditor/page/default -> /departments/auditor
/portal/group/treasurer/page/abc -> /departments/auditor
/portal/media-type/html/group/sheriff -> /departments/auditor
/portal/media-type/html/user/anon -> /departments/auditor

Tuckey URL rewrites is not an option to me. 

I would settle for a redirect to "/departments" if what I'm trying to achieve is not possible. I tried  Vanity URL like shown below but it's not working for me:

Uri: /portal/media-type/html/([A-Za-z0-9]+)
Forward To: /departments

Many thanks in advance for any hints.

Mark Pitely

unread,
Apr 29, 2021, 11:48:18 AM4/29/21
to dot...@googlegroups.com
One trick I use is hunting things down in the 404 page:
#set ($thispage=$request.getAttribute("javax.servlet.forward.request_uri"))
#if ($thispage.contains('/catalog'))
<meta http-equiv="Refresh" content="0; url=http://marywood.smartcatalogiq.com/" />
## alternatively you can: $response.sendRedirect($nrepath)
#end


I think you could also, in this case, make a structure of redirects and use the URLMap feature to match.
From your example, are you redirecting each and every one to the same place? I'd use the idea above.
But if each of those other links is supposed to map to a different place, you could absolutely use URL map and a structure to maname many calculated redirects.

Mark Pitely
Marywood University


--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/4441dd5a-c8e8-4dd4-ad38-0eff448de9bfn%40googlegroups.com.

Nathan Keiter

unread,
Apr 29, 2021, 11:54:22 AM4/29/21
to dot...@googlegroups.com
I think Apache or Nginx redirects would be ideal if you have access to them.


Probably not as easy if you are cloud hosted.

Nathan I. Keiter | Lead Network Applications Programmer | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993
https://www.gettysburg.edu<https://www.gettysburg.edu/>
________________________________
From: dot...@googlegroups.com <dot...@googlegroups.com> on behalf of Mark Pitely <pit...@maryu.marywood.edu>
Sent: Thursday, April 29, 2021 11:48 AM
To: dot...@googlegroups.com
Subject: Re: [dotcms] URL rewriting

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
________________________________
One trick I use is hunting things down in the 404 page:
#set ($thispage=$request.getAttribute("javax.servlet.forward.request_uri"))
#if ($thispage.contains('/catalog'))
<meta http-equiv="Refresh" content="0; url=http://marywood.smartcatalogiq.com/<https://linkprotect.cudasvc.com/url?a=http%3a%2f%2fmarywood.smartcatalogiq.com%2f&c=E,1,fQ8u0c3aS5uw7d-IyYIKTrBRuppbFqay-0UZqZoOkagGd_fBT1v0XYda2TJPDMc9mS6RivHuEbLWieWI0H_uz-N5tM9YiSuJO_-VhZYzCg,,&typo=1>" />
## alternatively you can: $response.sendRedirect($nrepath)
#end


I think you could also, in this case, make a structure of redirects and use the URLMap feature to match.
From your example, are you redirecting each and every one to the same place? I'd use the idea above.
But if each of those other links is supposed to map to a different place, you could absolutely use URL map and a structure to maname many calculated redirects.

Mark Pitely
Marywood University


On Thu, Apr 29, 2021 at 11:35 AM Mark Orciuch <mark_o...@ngsltd.com<mailto:mark_o...@ngsltd.com>> wrote:
Hello,

I am wondering if something like this is possible. I have some legacy urls coming from Google searches that need redirection. For example:

/portal/group/auditor/page/default -> /departments/auditor
/portal/group/treasurer/page/abc -> /departments/auditor
/portal/media-type/html/group/sheriff -> /departments/auditor
/portal/media-type/html/user/anon -> /departments/auditor

Tuckey URL rewrites is not an option to me.

I would settle for a redirect to "/departments" if what I'm trying to achieve is not possible. I tried Vanity URL like shown below but it's not working for me:

Uri: /portal/media-type/html/([A-Za-z0-9]+)
Forward To: /departments

Many thanks in advance for any hints.

--
http://dotcms.com<https://linkprotect.cudasvc.com/url?a=http%3a%2f%2fdotcms.com&c=E,1,SkT1aHvXxhOFzzyZHC501zh4QNQowFCxXCKQtaWDyYyHoM8zcehj5O7tSNT7OvaBwtiQAc5YogMYW6Zy0XH52OGQTxMUJ95xxM5Y_YTBU0Q8l_7gNU7FEA,,&typo=1> - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com<mailto:dotcms+un...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/4441dd5a-c8e8-4dd4-ad38-0eff448de9bfn%40googlegroups.com<https://linkprotect.cudasvc.com/url?a=https%3a%2f%2fgroups.google.com%2fd%2fmsgid%2fdotcms%2f4441dd5a-c8e8-4dd4-ad38-0eff448de9bfn%2540googlegroups.com%3futm_medium%3demail%26utm_source%3dfooter&c=E,1,q9WeLrpanRaPbsAOhNXpwUCLUkO-wmcqL8Iq5xlnCmrUtoBMJpZcfzyCt0rcAr4tUgT1QP83LJlx35NJayWoZbdC3-FLKbRgBQyuz5RRoA,,&typo=1>.

--
http://dotcms.com<https://linkprotect.cudasvc.com/url?a=http%3a%2f%2fdotcms.com&c=E,1,evFbAzsP20rOszFPFThqs880E82wXjo7Wywiu9c33tZz3jWNtso42Ze0QbWoZQ9EhDkTNdtcHwpmPemx-EHjRGs2erGamF0tmPNUVbKTt3o0rpcaEg,,&typo=1> - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com<mailto:dotcms+un...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/CAFeiKqOHjARfkKyNpf58rbXOSmYk2T4ttAqk%3Df5YDL94%2BJ%2Bv8A%40mail.gmail.com<https://linkprotect.cudasvc.com/url?a=https%3a%2f%2fgroups.google.com%2fd%2fmsgid%2fdotcms%2fCAFeiKqOHjARfkKyNpf58rbXOSmYk2T4ttAqk%253Df5YDL94%252BJ%252Bv8A%2540mail.gmail.com%3futm_medium%3demail%26utm_source%3dfooter&c=E,1,Lx-bpR46F6boHjYeCqAIAPxPnWwTPQ2kAMqgCO-G4vE4hP2foUJja9QJ4dRLNmK3MiET7wWZxRLyMdvXH56Y8zGQzoSGZtVTF11-MWir_tQgoBsZOA,,&typo=1>.

Mark Pitely

unread,
Apr 29, 2021, 11:57:13 AM4/29/21
to dot...@googlegroups.com
Also, be careful as '/portal' is a protected folder path in the dotCMS system.
If you did a broad redirect, you might break your access to the backend. By situating it as part of the 404 - it only triggers as a last resort.
M

--
http://dotcms.com - Open Source Java Content Management

---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/1619711659116.12002%40gettysburg.edu.

Mark Orciuch

unread,
Apr 29, 2021, 12:12:33 PM4/29/21
to dotCMS User Group
Thanks, this is a good advice. I currently have vanity url with uri "/portal/(?s).*/(?s).*" in place. So far, nothing is seems broken on the back end but I see your point. I will try your 404 page trick.

Mark Orciuch

unread,
May 1, 2021, 1:51:06 PM5/1/21
to dotCMS User Group
Mark, 

The strange problem that I'm having with the statement below is that sometimes it returns a random url (not the same url that sent the user to the 404 page). Almost as if it was getting attribute from another session.
 
#set($badurl = $request.getAttribute("javax.servlet.forward.request_uri"))

Other than that, the solution would work perfectly:

#set($badurl = $request.getAttribute("javax.servlet.forward.request_uri"))
## Sample legacy url: portal/group/clerk OR /portal/media-type/html/auditor/page/default
#if($badurl.indexOf("/group/") >= 0) 
    #set($path_array = $badurl.split('/'))
    #foreach($p in $path_array)
        #if($p == "group")
            #set($groupName = $path_array.get($velocityCount))
            ## Prevent infinite loop if the department does not exist
            #foreach($con in $dotcontent.pull("+contentType:Department +Department.legacyGroupName_dotraw:$groupName +deleted:false +working:true",1,"score,modDate desc"))
                <meta http-equiv="Refresh" content="0; url=$host/departments/$groupName/"/>
            #end
        #end
    #end
#end

Mark Pitely

unread,
May 3, 2021, 9:06:15 AM5/3/21
to dot...@googlegroups.com
Interesting. Good code.
Perhaps check the 404 page properties and turn off caching? dotCMS defaults to caching for 15 minutes which is absolutely not what you want to do here!

Mark Pitely
Marywood University

Mark Orciuch

unread,
May 3, 2021, 12:07:20 PM5/3/21
to dotCMS User Group
Hi Mark,

Your suggestion worked great! I've added "?dotcache=no" to my Forward To address on all the vanity URLs and so far the solution is 100% effective. Thanks again.

Mark Pitely

unread,
May 3, 2021, 12:15:03 PM5/3/21
to dot...@googlegroups.com
Yeah, the default cache-15 can be terrible if you are trying anything clever on your pages. A 404 page should *always* have some sort of custom reply built in based off of what was searched for. You can always use the manual cache on the page if you are really concerned.

M

Mark Orciuch

unread,
May 3, 2021, 1:40:22 PM5/3/21
to dotCMS User Group
Thanks again for the tip. Things are getting more clearer every day.
Reply all
Reply to author
Forward
0 new messages