AEM:URL缩短

时间:2015-03-10 15:16:06

标签: aem sling

我们有一个多语言网站,其结构类似于/content/<app>/<language>/login-page,我希望从网址中删除/content/<app>/<language>和.html,以便不会访问{{1}这样的网页或http://www.application.com/content/<app>/en/login-page.html我可以访问http://www.application.es/content/<app>/en/login-page.htmlhttp://www.application.com/login-page等网页。据我所知,必须在Apache中使用Sling Mappings和Rewrite Rules。但不完全确定如何实现这一目标。 apache和Sling Mappings的映射是什么?

1 个答案:

答案 0 :(得分:2)

这里有一篇很好的文章:

http://www.cognifide.com/blogs/cq/multidomain-cq-mappings-and-apache-configuration#.VP-psmSUc44

由于您有两个域,因此 etc / map 中需要两个映射。像这样:

{
   jcr: primaryType: "sling:OrderedFolder",
    www.application_com: {
     sling:internalRedirect: ["/content/application/en.html"],                               
     jcr:primaryType: "sling:Mapping",
     sling:match: "www.application.com/$"
    },
    www.application.com: {
      sling:internalRedirect: ["/content/application/en"],         
      jcr:primaryType: "sling:Mapping",
      redirect: {
         sling:internalRedirect: ["/content/application/en/$1","/$1"],
         jcr:primaryType: "sling:Mapping",
         sling:match: "(.+)$"
       }
    },
    www.application_es: {
     sling:internalRedirect: ["/content/application/es.html"],                               
     jcr:primaryType: "sling:Mapping",
     sling:match: "application.com/$"
    },
    www.application.es: {
      sling:internalRedirect: ["/content/application/es"],         
      jcr:primaryType: "sling:Mapping",
      redirect: {
         sling:internalRedirect: ["/content/application/es/$1","/$1"],
         jcr:primaryType: "sling:Mapping",
         sling:match: "(.+)$"
       }
    },
}

在网络服务器中重写.com的规则:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.application.com

        DocumentRoot /opt/cq/dispatcher/publish
        <Directory /opt/cq/dispatcher/publish>
            Options FollowSymLinks
            AllowOverride None
        </Directory>

        <IfModule disp_apache2.c>
            SetHandler dispatcher-handler
        </IfModule>
        RewriteEngine On
           RewriteRule ^/$ /content/application/en.html [PT,L]
           RewriteCond %{REQUEST_URI} !^/apps
           RewriteCond %{REQUEST_URI} !^/bin
           RewriteCond %{REQUEST_URI} !^/content
           RewriteCond %{REQUEST_URI} !^/etc
           RewriteCond %{REQUEST_URI} !^/home
           RewriteCond %{REQUEST_URI} !^/libs
           RewriteCond %{REQUEST_URI} !^/tmp
           RewriteCond %{REQUEST_URI} !^/var
           RewriteRule ^/(.*)$ /content/application/en/$1 [PT,L]
    </VirtualHost>    

在Web服务器中重写.es的规则:

  <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.application.es

        DocumentRoot /opt/cq/dispatcher/publish
        <Directory /opt/cq/dispatcher/publish>
            Options FollowSymLinks
            AllowOverride None
        </Directory>

        <IfModule disp_apache2.c>
            SetHandler dispatcher-handler
        </IfModule>
        RewriteEngine On
           RewriteRule ^/$ /content/application/es.html [PT,L]
           RewriteCond %{REQUEST_URI} !^/apps
           RewriteCond %{REQUEST_URI} !^/bin
           RewriteCond %{REQUEST_URI} !^/content
           RewriteCond %{REQUEST_URI} !^/etc
           RewriteCond %{REQUEST_URI} !^/home
           RewriteCond %{REQUEST_URI} !^/libs
           RewriteCond %{REQUEST_URI} !^/tmp
           RewriteCond %{REQUEST_URI} !^/var
           RewriteRule ^/(.*)$ /content/application/es/$1 [PT,L]
    </VirtualHost>      

[所有规则都改编自上述链接]

无扩展网址在Sling中无法工作,因此您必须从网络服务器重新编写网址以添加它们,然后     在aem中编写linktransformer以将其从html中的链接中删除,这里是指向解释此内容的帖子的链接     http://www.citytechinc.com/us/en/blog/2013/04/extensionless-urls-in-adobe-experience-manager.html