.htaccess将旧的url语法重定向到新的重写规则语法

时间:2014-05-25 10:00:30

标签: .htaccess mod-rewrite redirect

你好

我希望避免重复链接重定向所有链接都不会被.htaccess重写

例如:

.htaccess重写规则:

  

RewriteRule ^ watch - ([0-9] +)。html $ index.php?page = watch& id = $ 1 [NC,L]

使用变量重定向,类似于:

index.php?page=watch&id=$var **redirect to** watch-$var.html

2 个答案:

答案 0 :(得分:2)

尝试:

RewriteCond %{THE_REQUEST} \ /+index\.php\?page=watch&id=([0-9]+)
RewriteRule ^ /watch-%1.html? [L,R]

答案 1 :(得分:0)

这条规则怎么样:

RewriteRule ^index.html$ index.php [NC,L]
RewriteRule ^query.html$ query.php [NC,L]
RewriteRule ^search-([^/.-]+)\.html$ index.php?page=search&q=$1 [NC,L]
RewriteRule ^search-([^/.-]+)-([0-9]+)\.html$ index.php?page=search&q=$1&p=$2 [NC,L]
RewriteRule ^review-([0-9]+)\.html$ index.php?page=review&id=$1 [NC,L]
RewriteRule ^watch-([0-9]+)\.html$ index.php?page=watch&id=$1 [NC,L]
RewriteRule ^genre-([^/.-]+)\.html$ index.php?page=filter&genre=$1 [NC,L]
RewriteRule ^genre-([^/.-]+)-([0-9]+)\.html$ index.php?page=filter&genre=$1&p=$2 [NC,L]
RewriteRule ^Annee-([^/.-]+)\.html$ index.php?page=filter&Annee=$1 [NC,L]
RewriteRule ^Annee-([^/.-]+)-([0-9]+)\.html$ index.php?page=filter&Annee=$1&p=$2 [NC,L]
RewriteRule ^Origine-([^/.-]+)\.html$ index.php?page=filter&Origine=$1 [NC,L]
RewriteRule ^Origine-([^/.-]+)-([0-9]+)\.html$ index.php?page=filter&Origine=$1&p=$2 [NC,L]