首页 > 解决方案 > 这次重写缺少什么

问题描述

我有一个有几页的网站。我也有几个类别和子类别,我在 .htaccess 中尝试过 Mod Rewrite Rules,但它不起作用。用户和卖家的第二个重写规则有效,但类别重写规则不起作用。

我的设置是 Apache 服务器、PHP 系统、SQL 数据库。

这是我想要做的。

这是 PHP 中当前的类别链接结构

主要类别 https://www.inoconn.com/category?cat_id=2

子类别 https://www.inoconn.com/category?cat_child_id=17

我想要完成的是以下内容。

主要类别 https://www.inoconn.com/marketing/

子类别 https://www.inoconn.com/marketing/seo/

这是我的 htaccess 代码。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteRule ^category/([-\w]+)/(\d+)$ category.php?url=$1&page=$2 [NC,L]

RewriteRule ^([0-9a-zA-Z-_-]+)$ user.php?seller_user_name=$1

我想要完成的是以下内容。

标签: php.htaccessmod-rewrite

解决方案


在 .htaccess 文件顶部检查此规则

RewriteRule ^marketing/$ /category?cat_id=2 [L]
RewriteRule ^marketing/seo/$ /category?cat_child_id=17 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteRule ^category/([-\w]+)/(\d+)$ category.php?url=$1&page=$2 [NC,L]

RewriteRule ^([0-9a-zA-Z-_-]+)$ user.php?seller_user_name=$1

推荐阅读