在Apache中重写多个URL

时间:2018-04-24 16:22:50

标签: apache .htaccess url-rewriting

我一直在尝试很多组合来重写这三个实例网址

https://www.myjohara.com/jewelry?jwelurl=Rings
https://www.myjohara.com/collection?caturl=The-Global-Collection
https://www.myjohara.com/productdetails?purl=Pearl-Ball-Choker-Yellow-Gold

https://www.myjohara.com/Rings.html
https://www.myjohara.com/The-Global-Collection.html
https://www.myjohara.com/Pearl-Ball-Choker-Yellow-Gold.html

https://www.myjohara.com/jewelry/Rings.html
https://www.myjohara.com/collection/The-Global-Collection.html
https://www.myjohara.com/productdetails/Pearl-Ball-Choker-Yellow-Gold.html

我使用过这个仅适用于第一个条件的htaccess代码,即 https://www.myjohara.com/jewelry/Rings.html

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteRule ^([^/]*)\.html$ /jewelry?jwelurl=$1 [L]
RewriteRule ^([^/]*)\.html$ /collection?caturl=$1 [L]
RewriteRule ^([^/]*)\.html$ /productdetails?purl=$1 [L]

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

如果任何人在类似问题上需要帮助,这就是解决方案

RewriteRule ^collections/([^/]*)\.html$ /collection?caturl=$1 [L]
RewriteRule ^jewelrytype/([^/]*)\.html$ /jewelry?jwelurl=$1 [L]
RewriteRule ^products/([^/]*)\.html$ /productdetails?purl=$1 [L]

样本集合链接 - https://www.myjohara.com/collections/The-Global-Collection.html

样品珠宝类型链接 - https://www.myjohara.com/jewelrytype/Rings.html

示例产品链接 - https://www.myjohara.com/products/The-Drop-Diamond-Ring-Yellow-Gold.html