继续what i asked here我想自动重写以下网址
http://testsite.com/siterootb/sample-page.php?bbi=value1&bbl=value2
到
http://testsite.com/siterootb/sample-page/value1/value2
我的htaccess
现在看起来像
RewriteEngine on
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*) http://localhost%{REQUEST_URI}%1? [R=301,L]
###########################################################################
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/siterootb/([^/]+)/([^/]+)/([^/]+)
RewriteCond %{DOCUMENT_ROOT}/siterootb/%1.php -f
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+) $1.php?bbi=$2&bbl=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
我已经完成了URL Rewriting - Query String,url rewriting a query string,wordpress how to remove ? from the url using htaccess以及更多我从[query-string] [.htaccess]
获得的
答案 0 :(得分:1)
添加以下规则:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /siterootb/([^.]+)\.php\?bbi=([^&\ ]+)&bbl=([^&\ ]+)
RewriteRule ^ /siterootb/%1/%2/%3? [L,R=301]
您必须与%{THE_REQUEST}
变量匹配的原因是因为您希望按字面匹配请求的内容,而不是URI。 URI会随着规则的应用而变化,因此如果您与%{REQUEST_URI}
变量匹配,您将与另一条规则所做的更改进行匹配。