You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephen Nutbrown <st...@gmail.com> on 2016/05/02 11:51:05 UTC
Hyphens in URL possible?
Hi,
I am working on a tapestry project and someone has asked me to change the
URLs to include hyphens which they believe will improve SEO.
As per https://support.google.com/webmasters/answer/76329?hl=en, it's
supposedly good practise to "Consider using punctuation in your URLs. The
URL *http://www.example.com/green-dress.html
<http://www.example.com/green-dress.html>* is much more useful to us
than *http://www.example.com/greendress.html
<http://www.example.com/greendress.html>*. We recommend that you use
hyphens (-) instead of underscores (_) in your URLs."
So, let's say I have a page called: GreenDress, which has a GreenDress.java
and a GreenDress.tml.
Is there any way I can change that to "Green-Dress"? I'm not sure a hyphen
is even a valid character in a Java class name, so I assume there is
another way to do it?
Thanks,
Steve
Re: Hyphens in URL possible?
Posted by Stephen Nutbrown <st...@gmail.com>.
Carlos,
Many thanks for this - this is absolutely fantastic. Thank you for the
effort of posting this and the help. It'll take me a little bit of time to
digest it and fully understand how I can apply this to our exact project,
but it looks like everything I need is here!
Many thanks again, I really appreciate it.
Stephen Nutbrown
On 2 May 2016 at 11:38, Carlos Montero Canabal <
carlosmonterocanabal@gmail.com> wrote:
> Yes. I do it in many webapps.
>
> AppModule:
>
> @Contribute(PageRenderLinkTransformer.class)
> @Primary
> public static void provideURLRewriting(final
> OrderedConfiguration<PageRenderLinkTransformer> configuration) {
>
> configuration.addInstance(
> “MyLinkTransformer", MyLinkTransformer.class);
> }
>
> For simple pages (without context), I have a utility class with
> logicalPage name and the names into various languages (Spanish and English
> in the example) for better SEO on each language:
>
> private class PageLinkTransFormer {
>
> private final String logical;
>
> private final String linkEs;
>
> private final String linkEn;
>
> public PageLinkTransFormer(final String logical, final
> String linkEs, final String linkEn) {
> super();
> this.logical = logical;
> this.linkEs = linkEs;
> this.linkEn = linkEn;
> }
>
> public String getLogical() {
> return logical;
> }
>
> public String getLinkEs() {
> return linkEs;
> }
>
> public String getLinkEn() {
> return linkEn;
> }
>
> }
>
>
> And the MyLinkTransformer Service (in the example, I have the pages
> DevolucionesPage, AvisoLegalPage and SizeGuidePage):
>
> public class MyLinkTransformer implements
> PageRenderLinkTransformer {
>
> private static final String DEVOLUCIONES_LOGICAL_PAGE_NAME =
> "Devoluciones";
>
> private static final String DEVOLUCIONES_PAGE_URL_ES =
> "/envios-devoluciones-cuidados";
>
> private static final String DEVOLUCIONES_PAGE_URL_EN =
> "/delivery-return-cares";
>
> private static final String AVISO_LEGAL_LOGICAL_PAGE_NAME =
> "AvisoLegal";
>
> private static final String AVISO_LEGAL_PAGE_URL_ES =
> "/aviso-legal";
>
> private static final String AVISO_LEGAL_PAGE_URL_EN =
> "/disclaimer";
>
> private static final String SIZE_GUIDE_LOGICAL_PAGE_NAME =
> "SizeGuide";
>
> private static final String SIZE_GUIDE_PAGE_URL_ES =
> "/guia-tallas";
>
> private static final String SIZE_GUIDE_PAGE_URL_EN = "/size-guide";
>
> private final List<PageLinkTransFormer> links;
>
> @Inject
> private PageRenderLinkSource pageRenderLinkSource;
>
> @Inject
> private ContextValueEncoder contextValueEncoder;
>
> @Inject
> private ThreadLocale threadLocale;
>
> @Inject
> private PersistentLocale persistentLocale;
>
> public MyLinkTransformer() {
>
> links = new
> ArrayList<MyLinkTransformer.PageLinkTransFormer>();
>
> links.add(new PageLinkTransFormer(
> DEVOLUCIONES_LOGICAL_PAGE_NAME,
> DEVOLUCIONES_PAGE_URL_ES,
> DEVOLUCIONES_PAGE_URL_EN));
>
> links.add(new PageLinkTransFormer(
> AVISO_LEGAL_LOGICAL_PAGE_NAME,
> AVISO_LEGAL_PAGE_URL_ES,
> AVISO_LEGAL_PAGE_URL_EN));
>
> links.add(new PageLinkTransFormer(
> SIZE_GUIDE_LOGICAL_PAGE_NAME,
> SIZE_GUIDE_PAGE_URL_ES,
> SIZE_GUIDE_PAGE_URL_EN));
>
> }
>
> @Override
> public Link transformPageRenderLink(final Link defaultLink, final
> PageRenderRequestParameters parameters) {
>
> LOGGER.trace("transformPageRenderLink {} ({})",
> parameters.getLogicalPageName(), defaultLink.toAbsoluteURI());
>
> final String locale = threadLocale.getLocale().toString();
> for (final PageLinkTransFormer link : links) {
> if
> (link.getLogical().equals(parameters.getLogicalPageName())) {
> if ("es".equals(locale)) {
> return
> defaultLink.copyWithBasePath(link.getLinkEs());
> }
> else {
> return
> defaultLink.copyWithBasePath(link.getLinkEn());
> }
> }
> }
>
> return null;
> }
>
> @Override
> public PageRenderRequestParameters decodePageRenderRequest(final
> Request request) {
>
> String requestPath = request.getPath();
> if (persistentLocale.isSet()) {
> requestPath = requestPath.substring(3);
> }
>
> for (final PageLinkTransFormer link : links) {
> if (requestPath.equals(link.getLinkEn()) ||
> requestPath.equals(link.getLinkEs())) {
> return new
> PageRenderRequestParameters(link.getLogical(), new EmptyEventContext(),
> false);
> }
>
> }
>
> return null;
> }
>
> With context is simple to do it. I hope help you.
>
> Regards
>
> Carlos Montero
>
> > El 2/5/2016, a las 11:51, Stephen Nutbrown <st...@gmail.com>
> escribió:
> >
> > Hi,
> >
> > I am working on a tapestry project and someone has asked me to change the
> > URLs to include hyphens which they believe will improve SEO.
> >
> > As per https://support.google.com/webmasters/answer/76329?hl=en, it's
> > supposedly good practise to "Consider using punctuation in your URLs. The
> > URL *http://www.example.com/green-dress.html
> > <http://www.example.com/green-dress.html>* is much more useful to us
> > than *http://www.example.com/greendress.html
> > <http://www.example.com/greendress.html>*. We recommend that you use
> > hyphens (-) instead of underscores (_) in your URLs."
> >
> > So, let's say I have a page called: GreenDress, which has a
> GreenDress.java
> > and a GreenDress.tml.
> >
> > Is there any way I can change that to "Green-Dress"? I'm not sure a
> hyphen
> > is even a valid character in a Java class name, so I assume there is
> > another way to do it?
> >
> > Thanks,
> > Steve
>
>
Re: Hyphens in URL possible?
Posted by Carlos Montero Canabal <ca...@gmail.com>.
Yes. I do it in many webapps.
AppModule:
@Contribute(PageRenderLinkTransformer.class)
@Primary
public static void provideURLRewriting(final OrderedConfiguration<PageRenderLinkTransformer> configuration) {
configuration.addInstance(
“MyLinkTransformer", MyLinkTransformer.class);
}
For simple pages (without context), I have a utility class with logicalPage name and the names into various languages (Spanish and English in the example) for better SEO on each language:
private class PageLinkTransFormer {
private final String logical;
private final String linkEs;
private final String linkEn;
public PageLinkTransFormer(final String logical, final String linkEs, final String linkEn) {
super();
this.logical = logical;
this.linkEs = linkEs;
this.linkEn = linkEn;
}
public String getLogical() {
return logical;
}
public String getLinkEs() {
return linkEs;
}
public String getLinkEn() {
return linkEn;
}
}
And the MyLinkTransformer Service (in the example, I have the pages DevolucionesPage, AvisoLegalPage and SizeGuidePage):
public class MyLinkTransformer implements PageRenderLinkTransformer {
private static final String DEVOLUCIONES_LOGICAL_PAGE_NAME = "Devoluciones";
private static final String DEVOLUCIONES_PAGE_URL_ES = "/envios-devoluciones-cuidados";
private static final String DEVOLUCIONES_PAGE_URL_EN = "/delivery-return-cares";
private static final String AVISO_LEGAL_LOGICAL_PAGE_NAME = "AvisoLegal";
private static final String AVISO_LEGAL_PAGE_URL_ES = "/aviso-legal";
private static final String AVISO_LEGAL_PAGE_URL_EN = "/disclaimer";
private static final String SIZE_GUIDE_LOGICAL_PAGE_NAME = "SizeGuide";
private static final String SIZE_GUIDE_PAGE_URL_ES = "/guia-tallas";
private static final String SIZE_GUIDE_PAGE_URL_EN = "/size-guide";
private final List<PageLinkTransFormer> links;
@Inject
private PageRenderLinkSource pageRenderLinkSource;
@Inject
private ContextValueEncoder contextValueEncoder;
@Inject
private ThreadLocale threadLocale;
@Inject
private PersistentLocale persistentLocale;
public MyLinkTransformer() {
links = new ArrayList<MyLinkTransformer.PageLinkTransFormer>();
links.add(new PageLinkTransFormer(
DEVOLUCIONES_LOGICAL_PAGE_NAME,
DEVOLUCIONES_PAGE_URL_ES,
DEVOLUCIONES_PAGE_URL_EN));
links.add(new PageLinkTransFormer(
AVISO_LEGAL_LOGICAL_PAGE_NAME,
AVISO_LEGAL_PAGE_URL_ES,
AVISO_LEGAL_PAGE_URL_EN));
links.add(new PageLinkTransFormer(
SIZE_GUIDE_LOGICAL_PAGE_NAME,
SIZE_GUIDE_PAGE_URL_ES,
SIZE_GUIDE_PAGE_URL_EN));
}
@Override
public Link transformPageRenderLink(final Link defaultLink, final PageRenderRequestParameters parameters) {
LOGGER.trace("transformPageRenderLink {} ({})", parameters.getLogicalPageName(), defaultLink.toAbsoluteURI());
final String locale = threadLocale.getLocale().toString();
for (final PageLinkTransFormer link : links) {
if (link.getLogical().equals(parameters.getLogicalPageName())) {
if ("es".equals(locale)) {
return defaultLink.copyWithBasePath(link.getLinkEs());
}
else {
return defaultLink.copyWithBasePath(link.getLinkEn());
}
}
}
return null;
}
@Override
public PageRenderRequestParameters decodePageRenderRequest(final Request request) {
String requestPath = request.getPath();
if (persistentLocale.isSet()) {
requestPath = requestPath.substring(3);
}
for (final PageLinkTransFormer link : links) {
if (requestPath.equals(link.getLinkEn()) || requestPath.equals(link.getLinkEs())) {
return new PageRenderRequestParameters(link.getLogical(), new EmptyEventContext(), false);
}
}
return null;
}
With context is simple to do it. I hope help you.
Regards
Carlos Montero
> El 2/5/2016, a las 11:51, Stephen Nutbrown <st...@gmail.com> escribió:
>
> Hi,
>
> I am working on a tapestry project and someone has asked me to change the
> URLs to include hyphens which they believe will improve SEO.
>
> As per https://support.google.com/webmasters/answer/76329?hl=en, it's
> supposedly good practise to "Consider using punctuation in your URLs. The
> URL *http://www.example.com/green-dress.html
> <http://www.example.com/green-dress.html>* is much more useful to us
> than *http://www.example.com/greendress.html
> <http://www.example.com/greendress.html>*. We recommend that you use
> hyphens (-) instead of underscores (_) in your URLs."
>
> So, let's say I have a page called: GreenDress, which has a GreenDress.java
> and a GreenDress.tml.
>
> Is there any way I can change that to "Green-Dress"? I'm not sure a hyphen
> is even a valid character in a Java class name, so I assume there is
> another way to do it?
>
> Thanks,
> Steve
RE: Hyphens in URL possible?
Posted by Davide Vecchi <dv...@amc.dk>.
The JavaDoc for service interface org.apache.tapestry5.services.linktransform.PageRenderLinkTransformer seems to suggest it can be used for that. However this is just a guess and a pointer if you want to look at it, because I have no previous knowledge or experience with that. I'm sure you are going to get more accurate replies to this.
-----Original Message-----
From: Stephen Nutbrown [mailto:steveswfc@gmail.com]
Sent: Monday, May 2, 2016 11:51
To: Tapestry users <us...@tapestry.apache.org>
Subject: Hyphens in URL possible?
Hi,
I am working on a tapestry project and someone has asked me to change the URLs to include hyphens which they believe will improve SEO.
As per https://support.google.com/webmasters/answer/76329?hl=en, it's supposedly good practise to "Consider using punctuation in your URLs. The URL *http://www.example.com/green-dress.html
<http://www.example.com/green-dress.html>* is much more useful to us than *http://www.example.com/greendress.html
<http://www.example.com/greendress.html>*. We recommend that you use hyphens (-) instead of underscores (_) in your URLs."
So, let's say I have a page called: GreenDress, which has a GreenDress.java and a GreenDress.tml.
Is there any way I can change that to "Green-Dress"? I'm not sure a hyphen is even a valid character in a Java class name, so I assume there is another way to do it?
Thanks,
Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org