Sling 重写器的工作原理说明

2023-12-27

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

http://www.cognifide.com/blogs/cq/multidomain-cq-mappings-and-apache-configuration/ 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: "(.+)$"
     }
 }

1)但是,当我点击这个网址时:

 http://localhost:4503/products.html then I got 404 error. 

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

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

  http://localhost:4503/en/products.html. 

请告诉我是否可以按照上述方法

Update:我正在尝试通过调度程序访问。我在 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> 

3)现在,当我点击:localhost/content/geometrixx/en/products.html时,我会得到该页面,并且调度程序也会缓存该页面。但是,如果我导航到任何页面(例如“产品”->“三角形”),则由于 Sling 映射,URL 将变为 localhost:4503/products/triangle.html。这是预期的吗?由于dispatch不知道Sling映射,因此它不缓存triangle.html。如何使调度程序缓存工作?

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


我已经在 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",
    }
  }
}

我所做的唯一更改是第一个中的端口分隔符sling:match列 - 我已将其从冒号更改为点。为了确保我们正在使用相同的配置,我创建了一个包含我的配置的 CQ 包 http://newton.net.pl/store/geometrixx-localhost-mappings-1.0.zip.

这个配置做了三件事:

  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> and <form>标签将被映射到它们的短版本,例如:

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

将被重写为

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


关于你的第二个问题 - Sling 映射不允许将用户重定向到 URL 的映射版本。 Geometrixx 网站使用浏览器地图 http://dev.day.com/docs/en/cq/current/developing/mobile.html#Using%20BrowserMap%20On%20Your%20Pages库,它(除其他外)使用 JavaScript 将用户重定向到 URL 的缩短版本。这就是为什么输入以下 URL:

http://locahost:4503/content/geometrixx/en/products.html

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Sling 重写器的工作原理说明 的相关文章

随机推荐