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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分