吊索重写器如何工作澄清

Pak*_*ira 3 apache url-rewriting sling aem

我试图了解sling url重写是如何工作的.我正在关注这个网址 -

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

我在发布环境中完成的步骤 -

/etc/map.publish/http:

 jcr: primaryType: "sling:OrderedFolder",
 home: {
     sling:internalRedirect: ["/content/geometrixx/en.html"],
     jcr:primaryType: "sling:Mapping",
     sling:match: "localhost:4503/$"
 },
 localhost.4503: {
     sling:internalRedirect: ["/content/geometrixx/en"],
     jcr:primaryType: "sling:Mapping",
     redirect: {
         sling:internalRedirect: ["/content/geometrixx/en/$1","/$1"],
         jcr:primaryType: "sling:Mapping",
         sling:match: "(.+)$"
     }
 }
Run Code Online (Sandbox Code Playgroud)

1)然而,当我点击这个网址时:

 http://localhost:4503/products.html then I got 404 error. 
Run Code Online (Sandbox Code Playgroud)

2)此外,我想在用户点击此网址时实施:

  http://localhost:4503/content/geometrixx/en.html then it should open 

  http://localhost:4503/en/products.html. 
Run Code Online (Sandbox Code Playgroud)

请按照上述方法让我知道是否可行

更新: 我正试图通过调度员访问.我在Windows 7,CQ5.6.0上使用Apache 2.0.我的httpd.conf如下所示 -

 <IfModule disp_apache2.c>
 DispatcherConfig conf/dispatcher.any
 DispatcherLog    logs/dispatcher.log
 DispatcherLogLevel 3
 DispatcherNoServerHeader 0
 DispatcherDeclineRoot 0
 DispatcherUseProcessedURL 0
 DispatcherPassError 0
 </IfModule>
 <VirtualHost *:80>
   ServerName localhost
   DocumentRoot "C:/Apache2/htdocs/content/sitea"
   RewriteEngine On
   RewriteRule ^/$ /content/geometrixx/en.html [PT,L]
   RewriteCond %{REQUEST_URI} !^/apps
   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/geometrixx/en/$1 [PT,L]
    <Directory "C:/Apache2/htdocs/content/sitea">
     <IfModule disp_apache2.c>
           SetHandler dispatcher-handler
           ModMimeUsePathInfo On
         </IfModule>
         Options Indexes FollowSymLinks MultiViews
         AllowOverride all
         Order Allow,Deny
         Allow from all
 </Directory>
 </VirtualHost> 
Run Code Online (Sandbox Code Playgroud)

3)现在,当我点击:localhost/content/geometrixx/en/products.html然后我得到页面并且调度程序也缓存页面.但是,如果我导航到任何页面,例如Products - > Triangle,那么由于Sling映射,URL将变为localhost:4503/products/triangle.html.这是预期的吗?由于调度不了解Sling映射,因此它不会缓存triangle.html.如何使调度程序缓存工作?

4)由于重写规则在那里(RewriteRule ^ /(.*)$/content/geometrixx/en/$ 1 [PT,L]),如果我点击这个url localhost/triangle.html那么我应该得到正确的页面localhost/content/geometrixx/en/triangle.html但我收到404错误.

Tom*_*wek 5

我在CQ 5.6.1上使用了这些映射,它们似乎有效.请查找从我的实例导出的JSON:

{
  "jcr:primaryType": "sling:OrderedFolder",
  "home": {
    "sling:internalRedirect": "/content/geometrixx/en.html",
    "sling:match": "localhost.4503/$",
    "jcr:primaryType": "sling:Mapping",
  },
  "localhost.4503": {
    "sling:internalRedirect": "/content/geometrixx/en",
    "jcr:primaryType": "sling:Mapping",
    "redirect": {
      "sling:internalRedirect": [
        "/content/geometrixx/en/$1",
        "/$1"
      ],
      "sling:match": "(.+)$",
      "jcr:primaryType": "sling:Mapping",
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我做的唯一改变是第一sling:match列中的端口分隔符- 我已将其从冒号更改为点.为了确保我们正在使用相同的配置,我创建了一个包含我的配置CQ包.

这个配置做了三件事:

  1. 当用户请求时,http://localhost:4503/他们将被重定向到/content/geometrixx/en.html
  2. 当用户请求http://localhost:4503/products.html(或/content/geometrixx/en子树中的任何其他页面)时,它们将被重定向到/content/geometrixx/en/products.html.
  3. 在所有路径<a>,<img>并且<form>标签将被映射到它们的短版,例如:

<a href="/content/geometrixx/en/products.html">Products</a>

将改写为

<a href="/products.html">Products</a>


关于第二个问题 - Sling mappings不允许将用户重定向到URL的映射版本.Geometrixx站点使用BrowserMap库,其中(除其他外)使用JavaScript将用户重定向到缩短版本的URL.这就是输入以下网址的原因:

http://locahost:4503/content/geometrixx/en/products.html
Run Code Online (Sandbox Code Playgroud)

/products.html页面加载后会将您重定向到一秒钟.