.htaccess 仅当字符串等于特定值时,htaccess查询\u字符串重定向

.htaccess 仅当字符串等于特定值时,htaccess查询\u字符串重定向,.htaccess,.htaccess,我已经花了好几个小时研究如何做到这一点,感觉自己已经很接近了 我试图根据URL中传递的字符串参数将特定访问者重定向到我网站上的不同页面 对于exmaple,我希望URL mysite.com/index.php?src=msn&test=1被重定向到mysite.com/msn/index.php?src=msn&test=1 我计划让我的普通网站访问者访问index.php页面而不被重定向,因此只有当查询字符串与我设置的值匹配时,它才应该重定向 这是我的密码: Options +FollowS

我已经花了好几个小时研究如何做到这一点,感觉自己已经很接近了

我试图根据URL中传递的字符串参数将特定访问者重定向到我网站上的不同页面

对于exmaple,我希望URL mysite.com/index.php?src=msn&test=1被重定向到mysite.com/msn/index.php?src=msn&test=1

我计划让我的普通网站访问者访问index.php页面而不被重定向,因此只有当查询字符串与我设置的值匹配时,它才应该重定向

这是我的密码:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^src=msn(.*)$
RewriteRule ^(.*)$ http://www.mysite.com/msn/ [L]
当我转到URL mysite.com/?src=msn&test=1时,上面的代码可以工作,但它不适用于mysite.com/index.php?src=msn&test=1。当我进入index.php时,知道如何让它工作吗

谢谢

编辑:::

我的.htaccess文件中还有以下规则:

 ErrorDocument 404 /error404.php

 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /blog/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /blog/index.php [L]
 </IfModule>

 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
 RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L]
ErrorDocument 404/error404.php
重新启动发动机
重写库/博客/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/blog/index.php[L]
重新启动发动机
RewriteCond%{HTTP_HOST}^mywebsite\.com$[NC]
重写规则^(.*)$http://www.mywebsite.com/$1[R=301,L]
第一个是404重定向,第二个是wordpress文件更改,最后一个强制所有页面都更改。

这一行

重写规则^index.php$-[L]

阻止index.php进一步处理

最简单的解决方案是将新规则移到顶部,如下所示(我假设它们都在同一个.htaccess文件中)


您的htaccess中还有其他规则吗?Ulrich,我已经更新了原始帖子,在.htaccess文件中显示了其他规则。谢谢,这现在是有意义的。对于我对.htaccess的基本理解,我深表歉意,但我现在的问题是,我无法阻止规则应用于我所指向的页面,因此我进入了一个无限循环。知道如何解决这个问题吗?@user1167727在上面添加了一个额外的条件来防止出现这种情况
ErrorDocument 404 /error404.php

Options +FollowSymlinks
RewriteEngine on
RewriteBase /blog/

#rule to add www to domain
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L]

#new rule to redirect based on query string param
RewriteCond %{QUERY_STRING} ^src=msn(.*)$
#unless it is already msn
RewriteCond %{REQUEST_URI} !^/msn/ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/msn/ [L,R]

#rules for blogs
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]