如何使用.htaccess文件重定向url

时间:2013-09-20 08:55:50

标签: regex .htaccess mod-rewrite

如何重定向网址
1.从http://www.mysite.com/index.php?page=producthttp://www.mysite.com/product.html

AND

2.从http://www.mysite.com/index.php?page=product&id=example-examplehttp://www.mysite.com/product/example-example.html

1 个答案:

答案 0 :(得分:0)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

RewriteRule ^([^/]+)/([^.]+)\.html$ /index.php?page=$1&id=$2 [L,NC,QSA]