You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用.htaccess文件实现子目录URL重定向到带参数的PHP文件

.htaccess URL重定向配置方案

前提条件

  • 确认Apache服务器已启用mod_rewrite模块
  • 配置内容写入站点根目录的.htaccess文件即可生效

方案1:重定向至根目录下的stream.php

匹配/stream/[数字]/[文件名]格式的URL,301永久重定向到/stream.php?param1=数字&param2=文件名,配置如下:

RewriteEngine On
RewriteRule ^stream/([0-9]+)/([^/]+)$ /stream.php?param1=$1&param2=$2 [R=301,L]

如果不需要地址栏显示跳转后的参数地址,仅需内部静默转发,把R=301,删掉,仅保留[L]即可。


方案2:重定向至stream目录下的index.php

如果要跳转至/stream/index.php,配置如下:

RewriteEngine On
RewriteRule ^stream/([0-9]+)/([^/]+)$ /stream/index.php?param1=$1&param2=$2 [R=301,L]

同样,去掉R=301,即可实现静默内部重写。


内容的提问来源于stack exchange,提问作者Dream811

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 12:54:03