首页 > 解决方案 > 用 htaccess 重写查询字符串

问题描述

我需要重写这个网址

category.php?cat=computers

category/computers

或者,是不是反过来?

如何使用 .htaccess 做到这一点?

标签: php.htaccessmod-rewrite

解决方案


The rule is:

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

your .htaccess should look like this:

<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>

推荐阅读