【发布时间】:2013-10-20 21:03:43
【问题描述】:
首先我想说我一直在研究,但我仍然没有找到解决这个问题的方法。
我想做一个隐形重定向。使用此 URL http://www.localhost.com/@user_name/search/?q=string 进行搜索而不重定向到另一个页面,因为我应该检查 MySQL 数据库中的用户 @user_name 以检索其用户配置文件。
PHP 脚本搜索.php
<?php
echo 'USER:'.$_GET['user'].'<br/>';
echo 'QUERY q:'.$_GET['q'].'<br/>';
?>
.htaccess
#Begin invisibly redirect
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
#This works with this (www.localhost.com/@user_name/search/X55)
#RewriteRule ^@([_A-Za-z0-9]+)/search/X(.*)$ /profile/search/search.php?user=$1&q=$2 [L]
#But ,for search, this doesn't work with this (www.localhost.com/@user_name/search/?q=string)
RewriteRule ^@([_A-Za-z0-9]+)/search/?q=(.*)$ /profile/search/search.php?user=$1&q=$2 [L]
#END invisibly redirect
结果
1
有:
#RewriteRule ^@([_A-Za-z0-9]+)/search/X(.*)$ /profile/search/search.php?user=$1&q=$2 [L]
和
www.localhost.com/@user_name/search/X55
它返回
用户:用户名
查询 q:55/
2
有:
#RewriteRule ^@([_A-Za-z0-9]+)/search/?q=(.*)$ /profile/search/search.php?user=$1&q=$2 [L]
和
www.localhost.com/@user_name/search/?q=string
它给出了服务器错误。
请帮忙,谢谢。
【问题讨论】:
标签: php mysql .htaccess mod-rewrite