get params with clean url in multi hosting environment

五迷三道 提交于 2019-12-24 10:03:05

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/12745174/get-params-with-clean-url-in-multi-hosting-environment

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