GET参数用干净的URL在多主机环境 [英] get params with clean url in multi hosting environment

查看:129
本文介绍了GET参数用干净的URL在多主机环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网站根目录包含三个目录说 A,B,C 所有作为根不同的域

我在目录 B 创建一个的.htaccess 并添加下面的规则给它

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP
重写规则^([^ /] *)/([^ /] *)/ $ / B /样品页BBI = $ 1和;?桶= $ 2 [L]
 

在发生最后一行的上面,我也尝试过

 重写规则^ B /([^ /] *)/([^ /] *)$ / B /样品页面BBI = $ 1安培;桶= $ 2 [QSA, L]
 

使用上述规则

http://testsite.com/b/pageone.php 成功改写为

  http://testsite.com/b/pageone
 

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

被改写,而不是作为 http://testsite.com/b/sample-page?bbi=value1&bbl=value2

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

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

解决方案

您需要一个标志添加到您的其他规则:

 重写规则^(。*)$ $ 1.PHP [L]
 

要处理的其他情况,你需要在一个添加一条规则

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

这应该使它所以当你去 http://testsite.com/b/sample-page/value1/value2 ,你得到服务的内容 /b/sample-page.php?bbi=value1&bbl=value2

the website root contains three directories say a,b,c all acting as root for different domains

i created one .htaccess in directory b and added the following rules to it

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([^/]*)/?([^/]*)/$ /b/sample-page?bbi=$1&bbl=$2 [L]

In place of last line above, i have also tried

RewriteRule ^b/([^/]*)/([^/]*)$ /b/sample-page?bbi=$1&bbl=$2 [QSA,L]

Using above rules

http://testsite.com/b/pageone.php is successfully rewritten as

http://testsite.com/b/pageone

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

is rewritten as http://testsite.com/b/sample-page?bbi=value1&bbl=value2 instead of

http://testsite.com/b/sample-page/value1/value2 or

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

解决方案

You need to add an L flag to your other rule:

RewriteRule ^(.*)$ $1.php [L]

To handle the other situation, you'll need to add a rule before that one.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/b/([^/]+)/([^/]+)/([^/]+)
RewriteCond %{DOCUMENT_ROOT}/b/%1.php -f
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+) $1.php?bbi=$2&bbl=$3 [L]

This should make it so when you go to http://testsite.com/b/sample-page/value1/value2, you get served the content at /b/sample-page.php?bbi=value1&bbl=value2

这篇关于GET参数用干净的URL在多主机环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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