htaccess 将一系列 URL 屏蔽为更具可读性的版本,但显示来自原始 URL 的内容



这是一个电子商务商店的过滤器URL示例。

http://www.domain.com/showering/showers/filter/alliance
http://www.domain.com/showering/showers/filter/aquaflow
http://www.domain.com/showering/showers/filter/grohe
http://www.domain.com/showering/showers/filter/mira

我想知道是否有一种方法可以屏蔽这些URL,使它们看起来像:-

http://www.domain.com/alliance-showers
http://www.domain.com/aquaflow-showers
http://www.domain.com/grohe-showers
http://www.domain.com/mira-showers

但是仍然显示/showering/showers/* URL的页面内容?

然后我希望能够基于这些掩码URL设置规范URL。

我已经尝试了无数的变化,几乎没有成功,但这是我到目前为止得到的:-

RewriteEngine on
RewriteCond %{HTTP_HOST} !^/showering/showers/filter/(alliance)
RewriteRule (.*) /alliance-showers/

当这被应用到网站上时,Magento商店上的所有图像都不会偶然加载,而且URL根本不会改变。

回复@anubhava的评论…

。htaccess文件位于root目录或Magento安装目录下。它是文件中的第一条规则,像这样:-

############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^-]+)-([^/]+)/?$ /showering/$2/filter/$1 [L,R]

目前正在测试这个URL:-

http://www.showermania.co.uk/showering/showers/filter/alliance

想显示为:-

http://www.showermania.co.uk/alliance-showers

当前的答案对这个URL没有任何影响/改变。谢谢。

你可以使用这样的规则:

RewriteEngine on
RewriteRule ^showering/([^/]+)/filter/([^/]+)/?$ /$2-$1 [L,NC]

最新更新