0

以下 .htaccess 代码重定向我的客户动态(爆米花)产品页面,删除查询字符串,并将 URL 编码的“+”替换为更 SEO 友好的“-”。

RewriteEngine on
RewriteBase /

RewriteRule ^([^+\s]+)(?:[+\s]+)([^+\s]+)((?:[+\s]+).*)$ $1-$2$3 [DPI,N]
RewriteRule ^([^+\s]+)(?:[+\s]+)([^+\s]+)$ $1-$2 [R=301,DPI,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shop/popcorn/(.*)$ shop/popcorn/product.php?subject=$1 [L,B,NC]

生成的 URL 如下所示:

campbellssweets.com/shop/popcorn/Sea-Salt-and-Cracked-Pepper-Popcorn

我的问题是我是否/如何将相同的代码应用于商店目录中的其他文件夹:

IE

campbellssweets.com/shop/sweets/

campbellssweets.com/shop/cupcakes/

4

1 回答 1

0

让你的最后一条规则更通用一点:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(shop/[^/]+)/(.*)$ $1/product.php?subject=$2 [L,B,NC,QSA]
于 2013-09-30T11:55:15.230 回答