rewriting url with query string

。_饼干妹妹 提交于 2020-02-07 12:30:13

问题


in continuation to what i asked here i want to auto rewriting of below url

http://testsite.com/siterootb/sample-page.php?bbi=value1&bbl=value2

to

http://testsite.com/siterootb/sample-page/value1/value2

my htaccess now looks like

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]

i have gone through URL Rewriting - Query String, url rewriting a query string, wordpress how to remove ? from the url using htaccess and many more whichever i got from [query-string] [.htaccess]


回答1:


Add these rules:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /siterootb/([^.]+)\.php\?bbi=([^&\ ]+)&bbl=([^&\ ]+)
RewriteRule ^ /siterootb/%1/%2/%3? [L,R=301]

The reason you must match against the %{THE_REQUEST} variable is because you want to literally match against what is requested, not the URI. The URI changes as rules are being applied so you're going to match against a change that another rule has made if you match against the %{REQUEST_URI} variable.



来源:https://stackoverflow.com/questions/12755530/rewriting-url-with-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!