不工作htaccess的多个参数 [英] htaccess multiple parameters not working

查看:100
本文介绍了不工作htaccess的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新与htaccess文件,所以我好心问你的帮助:

I'm new with htaccess file, so I'm kindly asking you to help:

在我的htaccess的文件我有下一行:

In my htaccess file I have next lines:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^alpe-adria(.*)$ site/index.php$1 [L]
RewriteRule ^alpe-adria$ site/index.php?box=1&d=3 [L]

所以,首先我想设置索引文件,也就是在站点文件夹,以显示为字符串以上(ALPE-阿德里亚)。其次重写规则是我的登陆页面,其他页面具有相同的根在第一重写规则可见。当我localy测试这个规则,我的目标网页显示预期(键入本地主机/ ALPE-阿德里亚的浏览器)。不过,如果我要到其他页面,其中有例如这样的基本网址:

So, first I'm trying to set index file, that is in site folder, to show as string above (alpe-adria). Second RewriteRule is my landing page, other pages have same root as seen in the first RewriteRule. When I localy test this rules, my landing page shows as expected (typing localhost/alpe-adria in browser). But then if I want to go to other pages, which have for instance such basic URL:

的http://localhost/site/index.php D = 1&安培;箱= 1&安培; GRP = 306安培;水平= 1

重写规则的行为确定,这改写成

RewriteRule acts OK, rewriting this into

的http://本地主机/ ALPE-亚德里亚D = 1&安培;箱= 1&安培; GRP = 306安培;水平= 1

但网站史迪威留在我的登陆页面 - 就像是写在第二重写规则

but site stil stays on my landing page - like it is written in second RewriteRule

我也想设置一些的RewriteCond和添加其他重写规则:

I was also trying to set some more RewriteCond and adding another RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^alpe-adria?d=([^/]+)&box=([^/]+)&grp=([^/]+)&level=([^/]+)$ site/index.php?d=$1&box=$2&grp=$3&level=$4

和站点还是老样子不会改变。我究竟做错了什么?感谢您的帮助:)

and site stil doesn't change. What am I doing wrong? Thanks for any help :)

推荐答案

为什么不直接使用此规则(不附加任何条件)?

Why not just use this rule (without any conditions)?

RewriteCond %{QUERY_STRING} box=
RewriteRule ^alpe-adria$ /site/index.php [L]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^alpe-adria$ /site/index.php?box=1&d=3 [L]

查询字符串(之后的所有)将自动获得追加到结束时,如果你没有一个在规则中的目标。为什么你的规则是不工作的原因可能是以下条件:

The query string (everything after the ?) will automatically get appended to the end if you don't have a ? in your rule's target. The reason why your rules wasn't working is probably the conditions:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^alpe-adria(.*)$ site/index.php$1 [L]

我怀疑你实际上并没有一个名为/alpe-adria.php,这样的条件失败,因此该规则永远不会应用(否则,下一个可以工作过)。

I'm suspecting that you don't actually have a file called "/alpe-adria.php", thus the condition fails, and thus the rule is never applied (otherwise, that one might have worked).

您的第二个规则,有没有条件的,无非是:

Your second rule, which has no conditions, is simply:

RewriteRule ^alpe-adria$ site/index.php?box=1&d=3 [L]

而这其中的的追加查询字符串,因为你是硬编码为盒子= 1和d = 3。

And this one doesn't append the query string, since you are hardcoding it to "box=1" and "d=3".

这篇关于不工作htaccess的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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