2014-02-09 20 views
3

我想了解sling url重寫的工作原理。我下面這個網址 -sling重寫器的工作原理澄清

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. 

請讓我知道是否有可能按照上述方法

更新: 我試圖通過調度來訪問。我在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)現在,當我打:本地主機/內容/ geometrixx/EN/products.html放在然後我得到的頁面和調度員也緩存頁面。但是,如果我導航到任何頁面,例如產品 - >三角形,那麼由於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錯誤。

+0

有人可以幫忙嗎? –

回答

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", 
    } 
    } 
} 

我所做的唯一的變化是在第一sling:match列端口分隔符 - 我已經改變了它的形式結腸點。爲了確保我們正在使用相同的配置,我創建了一個CQ package containing my config

該配置使得3兩件事:

  1. 當用戶請求http://localhost:4503/當用戶請求http://localhost:4503/products.html(或任何其它頁面從/content/geometrixx/en子樹),他們將被重定向到/content/geometrixx/en/products.html它們將被重定向到/content/geometrixx/en.html
  2. <a>,<img><form>中的所有路徑將被映射到它們的短版本,例如,:

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

將被改寫,以

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


關於你的第二個問題 - 吊帶映射不允許用戶重定向到URL的映射版本。 Geometrixx網站使用BrowserMap庫,該庫(其中包括)使用JavaScript將用戶重定向到URL的縮短版本。這就是爲什麼進入以下網址:頁面加載後

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

將您重定向到到/products.html第二。

+0

非常感謝,讓我試試 –

+0

謝謝Tomek,您的解決方案一如既往!關於我的第二個問題,如果我想打開此頁面(http:// localhost:4503/products.html),當用戶點擊這個URL - http:// localhost:4503/content/geometrixx/en.html那麼我需要使用BrowserMap庫?是不是可以使用吊索:映射? –

+0

是的,Sling不提供此功能。你必須自己實現它或使用BrowserMap。 –