php - Htaccess 仅用于友好的 url

标签 php apache .htaccess mod-rewrite

我怎样才能只为友好的 url 重写 htaccess? 我有

RewriteRule ^products/([0-9]+)?$ show_a_product.php?product_id=$1    [NC,L]

我希望重定向 ONLY/products/1 这样的 url 但它也适用于 /show_a_product.php?product_id=1

最佳答案

你可以有另一个规则来阻止 /show_a_product.php?product_id=1 URI:

RewriteEngine On

RewriteCond %{THE_REQUEST} /show_a_product\.php[?/\s] [NC]
RewriteRule ^ - [L,R=404]

RewriteRule ^products/(\d+)/?$ show_a_product.php?product_id=$1 [QSA,NC,L]

关于php - Htaccess 仅用于友好的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34825704/

相关文章:

php - 是否可以将 index.html 推送到 heroku?

php - 向 AJAX 调用提供结果时 print_r 和 echo 有什么区别?

java - 将 Tomcat 7 升级到 8 后,Netbeans 不会添加新服务器

.htaccess - htaccess 从 %{HTTP_HOST} 获取域名到变量中,减去 www

.htaccess - 无法访问我的 Magento 文件夹中的 Magmi 子文件夹

php - 用于调试的变量中存储的查询不会显示

php - 为什么这不会插入表中?

apache - 如何使用 Apache Nutch 抓取 .pdf 链接

python - 虚拟环境错误的python版本

apache - 使用apache检查请求中是否存在 header