【发布时间】:2012-01-24 19:04:23
【问题描述】:
我一直在寻找如何做到这一点的几个小时,感觉好像我很接近了。
我正在尝试根据 URL 中传递的字符串参数将特定访问者重定向到我网站上的不同页面。
例如,我希望将 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]
第一个是404重定向,第二个是wordpress文件更改,最后一个强制所有页面为http://www。
【问题讨论】:
-
你的htaccess中还有其他规则吗?
-
Ulrich,我已经更新了原始帖子以在 .htaccess 文件中显示其他规则。
标签: .htaccess