使用htaccess修改购物车网址

时间:2012-08-02 22:38:27

标签: .htaccess url-rewriting rewrite

我有一个购物车,每个产品的网址太多。每个产品都可以有:例如:

http://www.mysite.com/12345_this_is_seo_product
http://www.mysite.com/this_is_category/12345_this_is_seo_product
http://www.mysite.com/this_is_category/this_is_subcategory/12345_this_is_seo_product

我想结束http://www.mysite.com/12345_this_is_seo_product 所以我假设要做的就是杀死.com/和最后/之间的所有内容。

但是,在导航类别的情况下,您可能会:

http://www.mysite.com/this_is_category/this_is_subcategory/

在您选择产品之前,这是可取的。

这意味着在.com和最终/之间的所有内容的剥离只能在产品上进行,并且唯一能够将产品与其他链接区分开来的事实是产品始于数字,如12345_this_is_seo_product

所以我需要的是一组表达式,它们会删除.com和最终/之间的所有内容,但只有在最后/之后是一组数字(总是四个)数字或更多)

希望我明白这一点,不要过多地解释它。

## edit - 添加我的htaccess -
Options +FollowSymlinks

Options -Indexes


<FilesMatch "\.(tpl|ini|log)">

 Order deny,allow

 Deny from all

</FilesMatch>


RewriteEngine On


RewriteBase /

RewriteRule ^.+/([0-9]+_[^/]+)$ /$1 [R=301,L]


RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]

RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)

RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

1 个答案:

答案 0 :(得分:0)

尝试将其放在文档根目录中的htaccess文件中:

RewriteEngine On
RewriteRule ^.+/([0-9]+-[^/]+)$ /$1 [R=301,L]