重写URL与查询字符串 [英] rewriting url with query string

查看:205
本文介绍了重写URL与查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在延续<一个href="http://stackoverflow.com/questions/12745174/get-params-with-clean-url-in-multi-hosting-environment">what我在这里问我想以下网址自动重写

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

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

我的的htaccess 现在看起来像

  RewriteEngine叙述上

的RewriteCond%{QUERY_STRING}!^ $
(。*)重写规则^ HTTP://本地主机%{REQUEST_URI}%1? [R = 301,L]

################################################## #########################
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^ / siterootb /([^ /] +)/([^ /] +)/([^ /] +)
的RewriteCond%{DOCUMENT_ROOT} /siterootb/%1.php -f
重写规则^ /([^ /] +)/([^ /] +)/([^ /] +)$ 1.PHP BBI = $ 2及?桶= $ 3 [L]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。*)$ $ 1.PHP [L]
 

我已经通过 URL重写了 - 查询字符串,的url重写查询字符串,<一个href="http://stackoverflow.com/questions/12721074/word$p$pss-how-to-remove-from-the-url-using-htaccess">word$p$pss如何删除?使用htaccess的和URL许多取其我从有更多的 [查询字符串] [的.htaccess]

解决方案

添加下列规则:

<?pre> 的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.

这篇关于重写URL与查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆