diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/BasePage.java | 13 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/RepositoryPage.java | 8 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index cb9de9fa..f8816831 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -88,6 +88,16 @@ public abstract class BasePage extends SessionPage { }
}
+ protected String getCanonicalUrl() {
+ return getCanonicalUrl(getClass(), getPageParameters());
+ }
+
+ protected String getCanonicalUrl(Class<? extends BasePage> clazz, PageParameters params) {
+ String relativeUrl = urlFor(clazz, params).toString();
+ String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
+ return canonicalUrl;
+ }
+
protected String getLanguageCode() {
return GitBlitWebSession.get().getLocale().getLanguage();
}
@@ -129,6 +139,9 @@ public abstract class BasePage extends SessionPage { @Override
protected void setHeaders(WebResponse response) {
+ // set canonical link as http header for SEO (issue-304)
+ // https://support.google.com/webmasters/answer/139394?hl=en
+ response.setHeader("Link" ,MessageFormat.format("<{0}>; rel=\"canonical\"", getCanonicalUrl()));
int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);
if (expires > 0) {
// pages are personalized for the authenticated user so they must be
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index 508b8654..68aa9a7a 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -39,7 +39,6 @@ import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.protocol.http.RequestUtils;
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.PersonIdent;
@@ -721,9 +720,7 @@ public abstract class RepositoryPage extends RootPage { String searchString = searchBoxModel.getObject();
if (StringUtils.isEmpty(searchString)) {
// redirect to self to avoid wicket page update bug
- PageParameters params = RepositoryPage.this.getPageParameters();
- String relativeUrl = urlFor(RepositoryPage.this.getClass(), params).toString();
- String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
+ String absoluteUrl = getCanonicalUrl();
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
return;
}
@@ -745,8 +742,7 @@ public abstract class RepositoryPage extends RootPage { // use an absolute url to workaround Wicket-Tomcat problems with
// mounted url parameters (issue-111)
PageParameters params = WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType);
- String relativeUrl = urlFor(searchPageClass, params).toString();
- String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
+ String absoluteUrl = getCanonicalUrl(searchPageClass, params);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
}
|