用htaccess重写查询字符串

时间:2018-06-02 21:04:40

标签: php .htaccess mod-rewrite

我需要重写这个网址

category.php?cat=computers

category/computers

或者,是反过来了吗?

如何使用.htaccess执行此操作?

1 个答案:

答案 0 :(得分:1)

规则是:

    RewriteRule    ^category/(.+)/?$    category.php?cat=$1    [NC,L]

你的.htaccess应该是这样的:

<IfModule mod_rewrite.c>
    #if the name of the php file is the same of the path, you have to remove MultiViews
    Options +FollowSymLinks -MultiViews          
    RewriteEngine on
    RewriteRule    ^category/(.+)/?$    category.php?cat=$1    [NC,L]    
</IfModule>