How to specify rewrite pattern in pages.xml - seam

I am having many xhtml files in several folders. I want to rewrite the url as
from http://localhost:8080/folder1/file1.seam to http://localhost:8080/folder1/file1
In file1.page.xml I gave
<rewrite pattern="/folder1/file1" />
The above provided me with the correct pattern. But i have many files and i don't want to specify this rewrite pattern in every page.xml file. Is there any way to specify this in pages.xml?
EDIT:
http://localhost:8080/folder2/file2.seam to http://localhost:8080/folder2/file2
http://localhost:8080/folder3/file3.seam to http://localhost:8080/folder3/file3
More samples of my translation

Rewriting occurs based on rewrite
patterns found for views in pages.xml
Seam URL rewriting does both incoming
and outgoing URL rewriting based on
the same pattern
Example:
<page view-id="/home.xhtml">
<rewrite pattern="/home" />
</page>
any incoming request for /home will be sent to /home.xhtml
any link generated that would normally point to /home.seam will instead be rewritten as /home
Rewrite patterns only match the portion of the URL before the query parameters
Both these will be matched
/home.seam?conversationId=13
/home.seam?color=red
Rewrite rules can take these query paramters into
consideration
<page view-id="/home.xhtml">
<rewrite pattern="/home/{color}" />
<rewrite pattern="/home" />
</page>
Incoming request for /home/red will be served as if it were a request for
/home.seam?color=red
If color is a page parameter an outgoing URLr /home.seam?color=blue would output as
/home/blue
Remember:
Rules are processed in order
List more specific rules before more general rules
If you want to hide the conversation id, you can do like this:
<page view-id="/search.xhtml">
<rewrite pattern="/search-{conversationId}" />
<rewrite pattern="/search" />
</page>
Now /search.seam?conversationId=16would be written as /search-16
If you want to match multiple pages use wildcards
<page login-required="true" view-id="/admin/*">
Hope this helps
Update
To answer your update question.
You can create wildcard rewriting with external rewriting but not with Seam's URL rewriting. With the view-based rewriting you would need to declare a pattern for each view id as you have described your self.
Sorry, but that just the way the cookie crumbles. :-)

yes, there is. Look at here.

Related

IIS outbound rule to change text within <span>

We are currently using URL rewrites to replace images and links. But we would like to replace some text contained within a tag. Has anyone achieved this before?
I did try to add a custom tag
<customTags>
<tags name="span">
<tag name="span" attribute="" />
</tags>
</customTags>
But wasn't sure what to add as the attribute if its just the text?
You cannot, as IIS URL Rewrite is only designed for URL rewrite.
If you do want to post-process requests, write a HttpModule or IIS module, and hook to the relevant events,
http://www.iis.net/learn/get-started/introduction-to-iis/iis-modules-overview

Redirect to internal page in MVC

I have a web site written in ASP.NET MVC 4.5
I have a controller called Products with views about each product.
I want with one of our products that when a user goes to www.website.com/ProductName redirects to www.website.com/Products/ProductName.
I am thinking right now this two approaches:
Create a Controller called like ProductName and use RedirectToRoute()
Modify the RouteConfig.cs file and add one.
What is your the best approach and why? Is there another?
I'm with #rjovic, definitely go with the second approach and add a new route.
The first approach would require creating a new controller for every product, which seems to go against good design principles; why have a separate class for multiple products that behave the same way? Routes are designed for exactly this kind of scenario: mapping a user-friendly URL scheme to the appropriate handlers in your application logic.
There are two possible approaches to designing the route in this case:
Match any URLs like /{ProductName}. The problem is this is a greedy scheme, so you'd want to put this near the end of the route lists, so that it would only be used in case no other schemes are matched.
Match only the URLs like /{ProductName} that match an actual product. So you'd have to pre-load the list of product names, and construct a constraint that would look like (for example) "[product1|product2|product3]".
It looks as though all you are doing here is some redirection. You might want to look at using the IIS Url Rewrite module and create a redirect rule such as
<rewrite>
<rules>
<rule name="Redirect to Products/ProductName">
<match url="^ProductName" />
<action type="Redirect" url="Products/ProductName" />
</rule>
</rules>
</rewrite>
There's plenty of information on http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/
www.website.com/products/productname would be more RESTful. Having your products at the root level of your website is only asking for trouble in the long run when you want to add another section of your site. i.e. www.website.com/about-us - is about-us a product, or it's own page?
Create a ProductsController and have a default action that takes a string that's a product name.

ASP.Net double URL Rewriting

I am using URL Rewriting to make my URLs more understandable(well, thats why it is used mostly).
But I would like to further rewrite them to make them even more understandable.
My home page is at /Pages/1/Home.aspx after rewriting with the below rule.
<rewrite url="~/Pages/(.+)/(.+).aspx" to="~/MainTemplate_$1.aspx?PageName=$2"/>
But I suppose it doesn't look good, at least for home page. So I have applied below rule again.
<rewrite url="~/index.aspx" to="~/Pages/41/Home.aspx"></rewrite>
But that doesn't work. Redirect instead of rewrite works, but the address bar would show clunky details which I don't want.
How do I make it work?
Thanks!
Just had to rearrange the rule order to get it working. Pretty straight forward.

ASP.net redirect rule

<rewrite url="~/forum/viewtopic.php\?t=([0-9]+)" to="~/Handlers/PermRedirect.ashx?ID=$1&action=forumpost" processing="stop"/>
This works great, but how to I make it redirect if t=([0-9]+) exists anywhere in the querystring?
Example URL's that it should match:
/forum/viewtopic.php?t=123&f=rgrg&rt=224
/forum/viewtopic.php?ty=345345&t=123&f=rgrg&rt=224
/forum/viewtopic.php?f=rgrg&rt=224&t=45
Can I make one rule to match them all? One ring, to rule them all.
Does this do the trick in your case?
url="~/forum/viewtopic.php\?.*t=([0-9]+).*

How do I determine if an asp.net url has been "rewritten"?

I'm using http://urlrewriter.net/ to rewrite urls at my website. For example, I'm rewriting:
http://www.example.com/schedule.aspx?state=ca
to
http://www.example.com/california.aspx
What I'm trying to do (for SEO purposes) to to dynamically add the meta tag:
<meta name="robots" content="noindex,follow" />
only to the page that hasn't been rewritten. This is because I want both URLs to work, but only the rewritten one to be indexed by search engines.
How do I determine which version of the page has been requested?
EDIT
Answers below suggest a 301 redirect instead of using a meta tag. Maybe I'll do this, but I still want to know the answer to the underlying question... how do I know if the page has been rewritten?
personally, I would 301 redirect from the un-rewritten one to the re-written one, and only use the single copy of the page. It is easier for users, and from an SEO perspective, you have 1 copy of the content.
If you need to do this you can probably do something like:
<add header="X-WasRewritten" value="true" />
And you can check for the header in your view and add the robots meta tag if you need it.
This will get returned to the client too, so if you want to hide that you can write a CustomAction (http://urlrewriter.net/index.php/support/reference/actions/custom-action) which will set some kind of state value in your request.
However, having two URIs for the same resource is something I would not recommend. I suggest you just keep the one representation. If you're worried about invalidating old bookmarks you can set the old one to redirect to the new one.
Further to chakrit's answer, it looks like UrlRewriter.NET stores the original URL in the HttpContext, in a key called UrlRewriter.NET.RawUrl. So, you could try something like:
bool isPageRewritten =
!string.IsNullOrEmpty(HttpContext.Current.Items["UrlRewriter.NET.RawUrl"]);
Most obvious method is to use the Request.Url object in your page to get information about the URL and query string. For example:
if (Path.GetFileName(Request.Url.FilePath) == "schedule.aspx")
//Not rewritten
else
//rewritten
I think that's the job of HttpContext.Current.Items.
You can save the "Redirection" in HttpContext.Current.Items and then in your pages, you can check it for a certain added value.
I believe you can add hooks to urlrewriter.net that could do it, something alongs:
HttpContext.Current.Items["Redirected_From"] = currentUrlHere;
And then in your webpages, you could check it by:
if (!string.IsNullOrEmpty(HttpContext.Current.Items["Redirected_From"]))
// the page's been redirected, do something!
else
// no it's visited normally.
I have long since left it for the ASP.NET Routing framework in .NET 3.5 SP1, it is better than urlrewriter.net IMO.

Resources