大网数据广告活动
网站运营与故障问答

Htaccess - replacing a query string with a numeric value

· 52CE 我爱测

I don't know why but this htaccess item doesn't work for me. I have something like this after update user profile public/user_profile/show_user.html?id=4 and I want to have public/user_profile/show_user.html/4 htaccess RewriteRul…

问题原文

原帖链接 · Mantykora 7 · CC BY-SA 4.0

I don't know why but this htaccess item doesn't work for me. I have something like this after update user profile public/user_profile/show_user.html?id=4 and I want to have public/user_profile/show_user.html/4

  1. htaccess

RewriteRule ^show_user.html/(\d+)$ show_user.php?id=$1 [NC,L]

  1. profile.php

    After update user -> redirect to user detail

redirect_to(url_for('/user_profile/show_user.html/' . $id));

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

I want to have public/user_profile/show_user.html/4

RewriteRule ^show_user.html/(\d+)$ show_user.php?id=$1 [NC,L]

Assuming public/ is the document root and this .htaccess file is in the document root then you are missing /user_profile from the start of the RewriteRule pattern. For example:

RewriteRule ^user_profile/show_user\.html/(\d+)$ show_user.php?id=$1 [L]

Don't forget to backslash escape literal dots. You shouldn't need the NC flag here.

This directive also needs to be near the top of your .htaccess file, before any front-controller. Order matters.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-02-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。