我想了解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: "(.+)$"
}
}
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)现在,当我点击:localhost / content / geometrixx / en / products.html然后我得到页面并且调度程序也缓存页面。但是,如果我导航到任何页面,例如Products - &gt; 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错误。
答案 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件事:
http://localhost:4503/
时,他们将被重定向到/content/geometrixx/en.html
http://localhost:4503/products.html
(或/content/geometrixx/en
子树中的任何其他页面)时,他们将被重定向到/content/geometrixx/en/products.html
。<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
在页面加载后,会将您重定向到/products.html
。