doutou3725 2015-09-16 11:22
浏览 27

.htaccess remove * .php抛弃作为GET参数传递的URL的参数

My request is quite simple. Using my current .htaccess conditions and rules as given here:

# Remove .php extension from URLS
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Redirect from *.php to URL without *.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

Problem is, when I pass a URL that contains *.php?param1=A&param2=B as a parameter, it throws away "?param1=A&param2=B"

For example: I want to redirect to: "/views/users/login.php?redirect=/views/home.php?id=1" Resulting in: "/views/users/login?redirect=/views/home", which throws away "?id=1", so now I can not access that parameter.

How do I rewrite my rules so that it keeps those parameters?

Any suggestions are welcome and much appreciated.

Update (2015-09-16):

Removing

RewriteRule ^(.*)\/index\.php$ $1 [R=301,L,NC]

As it is irrelevant.

  • 写回答

3条回答 默认 最新

  • doutou19761022 2015-09-16 11:59
    关注

    Hello you just need to add the query append marker like so:

    RewriteRule ^(.*)\/index\.php$ $1 [QSA,R=301,L,NC]
    

    that is "QSA"

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)