.htaccess - 带有 htaccess 的 Preety 网址
问题描述
我有网址localhost/product/q.php?id=1&product=my-product
如何使 urllocalhost/product/1/my-product
使用 .htaccess
解决方案
您使用RewriteRule
由正则表达式组成的 a 应用到用户访问的漂亮 URL和随后将由服务器/脚本使用的替换。
RewriteRule ^product/(\d+)/(.*)$ /product/q.php?id=$1&product=$2 [L]
RewriteRule : Type of action
^product/(\d+)/(.*)$ : Regex to run against URL
/product/q.php?id=$1&product=$2 : Replacement URL
[L] : Flags; L == Last
笔记
重新阅读问题后,您可能需要添加:
Options -MultiViews
到你的.htaccess
文件的顶部。
推荐阅读
- c++ - VS2008中不出现红色曲线
- javascript - 在 NodeJS 中同时输入和输出
- javascript - 将 Material-ui ToggleButtonGroup 连接到 redux-form
- python - 基本的python问题:制作一个简单的骰子游戏
- python - Python select.select 不暂停执行
- jenkins - 如何根据詹金斯中的选择显示输入框?
- javascript - 我希望我的导航栏在我向下滚动时消失并在我向上滚动时出现。导航栏是固定的。怎么了?
- ruby - NameError:irb 控制台上未初始化的常量用户
- r - setwd 中的警告消息 - R
- python - Heroku - 调度程序烧瓶