使用htaccess使用get变量重定向url

时间:2014-03-17 20:47:02

标签: .htaccess redirect

我正在尝试重定向此链接:http://www.example.com/articles.php?article_title=this-is-an-article

http://www.example.com/articles/this-is-an-article

到目前为止,我的.htaccess文件中的内容似乎不起作用:
         RewriteEngine On     RewriteBase /

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Options -Indexes

RewriteRule ^articles/([a-z\-]+)$ articles.php?article_title=$1


提前致谢

1 个答案:

答案 0 :(得分:0)

试试这段代码:

Options -Indexes -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{THE_REQUEST} \s/+articles\.php\?article_title=([^&\s]+) [NC]
RewriteRule ^ /articles/%1? [R=301,L,NE]

RewriteRule ^articles/([a-z-]+)/?$ articles.php?article_title=$1 [L,QSA,NC]