php - 这次重写缺少什么
问题描述
我有一个有几页的网站。我也有几个类别和子类别,我在 .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
我想要完成的是以下内容。
解决方案
在 .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
推荐阅读
- javascript - 尝试使用淘汰赛 javascript 让自动完成工作
- php - cURL 请求不显示任何内容
- r - R - 修复多折线图的图例和其他绘图特征
- mongodb - 在spring数据mongodb中转换MongoDb查询
- c# - Linq 查询:通过子查询与 count() 组进行内部连接
- spring - 如何在@Controller 中让静态内容通过并转发非静态内容请求?
- python - python生产,建议创建一个新用户并授予它sudo权限开始?
- javascript - Google 表格脚本 - 一个按钮,具有两个连续功能(功能 1 运行,结束,然后功能 2 运行)
- postgresql - TypeORM:在 PostgreSQL 中使用原始 SQL 时出现 QueryFailedError
- javascript - 使用 rails 和 turbolinks 5 更改页面时出现 Froala 工具栏错误