首页 > 解决方案 > 带有 htaccess 的 Preety 网址

问题描述

我有网址localhost/product/q.php?id=1&product=my-product

如何使 urllocalhost/product/1/my-product使用 .htaccess

标签: .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文件的顶部。


推荐阅读