通过htaccess重写URL

时间:2015-09-18 17:42:19

标签: .htaccess mod-rewrite url-rewriting

我在以下结构中有一个网址,如

http://www.naturaflowers.com/100-fresh-cut-wholesale-flowers.html

我想重写像

这样的网址
http://www.naturaflowers.com/fresh-cut-wholesale-flowers.html

我们使用"终极SEO url插件"生成SEO友好的URL。旧的URL结构是/index.php?main_page=index&cPath=category_id。我的htaccess代码如下:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-(.*).html$ index\.php?main_page=index&cPath=$1&%{QUERY_STRING} [L]
  

上面提到的插件和这个htaccess代码重写   index.php?main_page = index& cPath = 100 to   /100-fresh-cut-wholesale-flowers.html。现在我想   /100-fresh-cut-wholesale-flowers.html重写为   /fresh-cut-wholesale-flowers.html我的网站到处都是   htaccess。

2 个答案:

答案 0 :(得分:0)

RewriteRule ^(/?)\d+-(.*)$ $1$2

答案 1 :(得分:0)

你的规则如下:

RewriteEngine On
RewriteBase /

RewriteRule ^[0-9]+-(.+?\.html)$ /$1 [L,R=302,NC]

RewriteRule ^(.+?)\.html$ index\.php?main_page=index&cPath=$1 [L,QSA,NC]