且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重写URL与查询字符串

更新时间:2023-02-24 09:21:30

添加下列规则:

的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ / siterootb /([^] +)\ PHP \ BBI =([^&放大器; \ 〕+)及桶=([^&安培; \] +) 重写规则^ / siterootb / 1%/ 2%/ 3%? [L,R = 301]

您必须对%匹配的原因{THE_REQUEST} 变量是因为你想从字面上反对什么要求,而不是URI匹配。正在应用的URI变化规则,所以你要匹配的变化的另一条规则作出,如果你匹配对%{REQUEST_URI} 变量。

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]

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.