dpzr52746 2014-04-25 23:31
浏览 38
已采纳

在.htaccess重定向中包含GET变量

Here is my .htaccess code:

#Rewrite settings
Options +FollowSymlinks
RewriteEngine on

#Remove index.php from url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

#Add trailing slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

#Make entire url variable
RewriteRule ^(.*/)$ /index.php?path=$1 [R=301]

I would like to redirect all requests for files name "index.php" in any of the sub directories to the root "index.php" with the path as a get variable. So:

http://mywebsite.com/this/is/the/path/index.php
becomes:
http://mywebsite.com/index.php?path=this/is/the/path/

This currently works. However, the problem is that if the original url has GET variables in it, they are removed and not included in the path. So:

http://mywebsite.com/this/is/the/path/index.php?get=variables
should become:
http://mywebsite.com/index.php?path=this/is/the/path/%3Fget%3Dvariables

How can this be done? I am new to URL rewriting and can't seem to get my code to behave in this way.

Thanks for your help.

  • 写回答

1条回答 默认 最新

  • dongshi1914 2014-04-26 04:57
    关注

    You just need to add query string append (QSA) flag like this:

    RewriteRule ^(.*/)$ /index.php?path=$1 [R=301,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化