Redirect front page with 301 using Prettyfaces - jsf

I use jsf 2.2 & prettyfaces-jsf 2-3.3.3 and have /pages/index.xhtml page.
I try redirect from front page to another like this:
<rewrite match="/" url="http://somesite.net" redirect="301" />
Of course, all the pages are redirected. What is the right way redirect only front page?

The match attribute is a regular expression. So you should try something like this instead:
<rewrite match="^/$" url="http://somesite.net" redirect="301" />

Related

How to redirect(Bidirectional way) using pages.xml by EL methods in JSF and Seam project?

I'm facing a problem while rewriting the pattern in pages.xml dynamically.
I have a mainmenu and submenus on the webpage, I have a scenario like when user give's www.website.com/mainmenu/submenu1 , EL method should execute and rewrite that particular page dynamically.Because all the menus and submenu's will come from backend. Also it should work from home page when user select submenu item. I mean, it should work in both the ways(bidirectional).
Critical part is, how to execute and get the /mainmenu/submenu names from backend when user enter's url in address bar. This must use pages.xml only by using seam framework.
Thanks in advance!! Please let me know if my explanation is not clear.
Try reading the seam docs....
<page view-id="/yourPage.xhtml">
<rewrite pattern="/{mainmenu}/{submenu}"/>
<param name="mainMenu" required="true" value="#{yourBean.mainMenu}"/>
<param name="subMenu" required="false" value="#{yourBean.submenu}"/>
<action execute="#{yourBean.processPage}" on-postback="false"/>
</page>
SEAM Documentation

Different urls mapping to the same xhtml file

With jsf 2.x I want to use urls like
../admin1.xhtml
../admin2.xhtml
../admin3.xhtml
that should all call the same xhtml file (generic.xhtml), but with a parameter like this:
../generic.xhtml?page=admin1
../generic.xhtml?page=admin2
../generic.xhtml?page=admin3
instead of creating a lot of useless identical xhtml files to serve the requests. How can i better achieve that with jsfs? Am i bound to write loads of xml or can i make a simple rule in faces-config.xml, or should i use some other tools?
Make use of PrettyFaces url prettyfier. First of all it'll allow you removing your file extensions, which is considered a best practice (you would be able to change your backend framework without altering the urls themselves).
Apart from that, there's the chance to integrate the parameter itself into the url:
<!-- Maps "/admin/#{page}" to the URL "/generic.xhtml?page=value" -->
<url-mapping id="admin-view">
<pattern value="/admin/#{page}" />
<view-id value="/generic.xhtml" />
</url-mapping>
So you'll be able to type:
/admin/admin1
And that will drive you to:
/generic.xhtml?page=admin1

Pretty faces: one mapping configuration for multi .xhtml page

I have one question. How could pretty faces do this:
<code>
<url-mapping id="home">
<pattern value="/viewer" />
<view-id value="/pages/*" />
</url-mapping>
</code>
Well, I wonder if pretty faces could hide paths of all .xhtml in folder using just one configuration as shown as above, instead of to config for each and every file.
This mapping doesn't make any sense. To which view should PrettyFaces forward if the client requests /viewer?
However, you can do something similar with Rewrite, which is the successor of PrettyFaces. With Rewrite you can do something like:
.addRule( Join.path("/viewer/{page}").to("/pages/{page}.xhtml") )
This will basically map your URLs like this:
/viewer/foo -> /pages/foo.xhtml
/viewer/bar -> /pages/bar.xhtml
/viewer/whatever -> /pages/whatever.xhtml
If you want to migrate your app to Rewrite, which is really simple, have a look at the PrettyFaces Migration Guide.

Rewriting URLs using pretty-config

I am facing problem with rewriting urls using pretty-config.xml and I want help. This is what I want.
I want to render the URL as:
http://www.example.com/{productId}
and the page actual URL is:
http://www.example.com/page/product.jsf
In short, I have one page but I want to render it each time as different url based on product id from the backing bean.
Sounds fairly simple. I would use this:
<url-mapping>
<pattern value="/#{productId}" />
<view-id value="/pages/product.jsf" />
</url-mapping>
Just make sure that you generate the correct links in your pages upon rendering.

Use .htaccess to give form submissions clean URLs

I'd like to rewrite form submissions to clean URLs, so that example.com/search/go?term=foo becomes example.com/search/foo
How do I do this?
Use JavaScript:
<input type="text" id="search_term" />
<input type="button" value="Search" onclick="goSearch()" />
<script type="text/javascript">
function goSearch() {
var term = document.getElementById("search_term");
window.location = "http://example.com/search/" + escape(term);
}
</script>
URL encode the query string, and redirect to the desired path.
You can change the URL that is called in the action attribute of the form element in HTML. Alternatively, you could set it in an OnClick JavaScript event handler on a button.
You don't need mod_rewrite and .htaccess to accomplish this.
Though, you could use mod_rewrite to redirect everything that's not a document to an index controller script and do the translation there.
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
That's how Zend Framework does it, and actions look like example.com/search/foo instead of example.com/search/go?term=foo. Of course, search would need to be a script.

Resources