我正在尝试使用htaccess将http://test.pearlsquirrel.com/explore_all?u=hiphop重定向到http://test.pearlsquirrel.com/explore_all/hiphop。但是,它会在此处重定向:http://test.pearlsquirrel.com/explore_all/?u=site_error.php。我已经遍布Stackoverflow寻找答案,但我似乎无法找到它。我真的很感激帮助解决这个问题,谢谢!
这是我的.htaccess文件
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]
答案 0 :(得分:2)
你可以试试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} [^=]+=([^=]+)
RewriteRule .* /%1? [L]
将映射:
http://test.pearlsquirrel.com/explore_all?u=hiphop
对此:
http://test.pearlsquirrel.com/explore_all/hiphop
用此文件替换.htaccess文件中的相应代码。
我没有检查.htaccess文件中的规则。
方法强>
现在,如果是相反的方式,我认为是这样,并且想法是映射这个传入的URL:
http://test.pearlsquirrel.com/explore_all/hiphop
到此资源:
http://test.pearlsquirrel.com/explore_all?u=hiphop
将上述规则集替换为以下规则:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L]