Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:54:13+00:00 2026-05-28T18:54:13+00:00

I would like to basically do a URL rewrite in UrlMappings.groovy, for example: /pub/cdn/$version/**(uri:

  • 0

I would like to basically do a URL rewrite in UrlMappings.groovy, for example:

"/pub/cdn/$version/**"(uri: request.forwardURI.replaceFirst("/pub/cdn/[0-9]*", ""))

So that a request for:

/pub/cdn/1327516405188/css/login.css

for example, would get translated to:

/css/login.css

The idea is to take the original URI and strip out some of the path, and pass along the new URI.

However, using the above code, I get the error:

>    org.springframework.beans.factory.BeanCreationException: Error
>    creating bean with name 'grailsUrlMappingsHolder': Cannot resolve
>    reference to bean 'urlMappingsTargetSource' while setting bean
>    property 'targetSource'; nested exception is
>    ...
>    groovy.lang.MissingPropertyException: No such property: forwardURI for
>    class: java.lang.String

which seems to imply that the request object is a String. Is there a way to obtain the original URI in UrlMappings.groovy?

The “/old/path”(uri: “/new/path”) method does work as long as the new path is hard coded, but I can’t figure out how to access the original requested path as a variable inside the UrlMappings class.

P.S. I tried having UrlMappings call a controller:

"/pub/cdn/$version/**" {
    controller = "image"
    action = "cdnRedirect"
}

and in the Controller:

def cdnRedirect = {
    def newUri = request.forwardURI?.toString().replaceFirst("/pub/cdn/[0-9]*", "")
    return redirect(uri: newUri)
}

While the controller closure gets called correctly, and the URI gets translated correctly, the redirect does not seem to do anything at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:54:13+00:00Added an answer on May 28, 2026 at 6:54 pm

    Based on your example, it sounds to me like you are solving the wrong issue. The real issue here is seems to be that you are using relative links (e.g. css/login.css) to static content. When the browser picks up a relative link, it uses the current url to determine the file’s path.

    However, if you use Grails’ resource tag, grails will generate a URL that is anchored to the root of the URL. For example, your css/login.css link would become /myAppName/css/login.css.

    Usage is like so:

    <link type="text/css" href="${resource(dir: 'css', file: 'login.css')}" />
    

    This guarantees that, no matter the controller, action, or other ID information, the link to the CSS file will always be correct.


    As for why your UrlMapping isn’t working, it’s because it isn’t dynamically processed. It’s processed during application startup, and so the request object doesn’t even exist at that time.

    If you absolutely need a URL rewriting system, and using a controller to process the resources is too complex for this purpose, I recommend putting your servlet engine (i.e. Tomcat) behind Apache and just using mod_rewrite. Properly designed, however, this really shouldn’t be necessary.


    Edit

    Just for complete information, to get dynamic control of the mapping is to use the syntax specified in Dynamic Controller and Action Names. However, this is somewhat limited, and you still can’t use it to perform a redirect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically would like to load an image from a url to an activity
I would like to create a custom data type which basically behaves like an
Basically I would like to store the address of a pointer in a buffer.
Basically I would like to tell MSTest to execute a bit of code before
I would like to do the following. Basically have a stored procedure call another
I would like to use databinding when displaying data in a TextBox. I'm basically
I would like to add a preprocessor to HTML pages. Basically, I have a
I would like to have fuzzy looking border around my Canvas control. Basically, I
Basically, I would like a brief explanation of how I can access a SQL
Basically, I would like to build a list comprehension over the cartesian product of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.