URL重写结束时间 [英] Apache mod_rewrite ending periods

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

问题描述

我想更好地了解Apache的mod_rewrite,和我有意想不到的效果。我尝试过很多不同的EX pressions,但似乎没有任何表现我怎么知道它应该。

I am trying to better understand Apache's mod_rewrite, and am having unexpected results. I've tried many different expressions, but nothing seems to behave how I understand it should.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]

使用 www.domain.com/item1/item2/item3 收益率 ITEM1 / ITEM2 /项目3
使用 www.domain.com/item1/item2/item3.php 收益率 ITEM1 / ITEM2 / item3.php
使用 www.domain.com/item1/item2/item3 ........... 收益率 ITEM1 / ITEM2 /项目3

Using www.domain.com/item1/item2/item3 yields item1/item2/item3
Using www.domain.com/item1/item2/item3.php yields item1/item2/item3.php
Using www.domain.com/item1/item2/item3........... yields item1/item2/item3

为什么不 ITEM1 / ITEM2 /项目3 ...........

Why is it not item1/item2/item3...........?

奇怪的是,如果该URL为 www.domain.com/item1/item2/item3 ..........一个,该航线是我预计, ITEM1 / ITEM2 /项目3 ..........一个

Strangely, if the URL is www.domain.com/item1/item2/item3..........a, the route is what I expect, item1/item2/item3..........a

我已经尝试了一些其他的常恩pressions,但他们采取同样行动。

I've tried a few other regular expressions, but they act similarly.

感谢你。

推荐答案

虽然我还没有找到任何文件,解释为什么阿帕奇/的.htaccess / mod_rewrite的行为就这样,我有一个选择,如果有人遇到这种

While I still haven't found any documentation explaining why Apache/.htaccess/mod_rewrite behaves this way, I do have an alternative, in case anyone comes across this.

而不是使用的.htaccess通过所要求的文件名,查询字符串变量,如在我上面的问题的路线的,在PHP中有可以使用一些服务器变量。所以,我改变了我的逻辑的index.php读取查询字符串为:

Instead of using .htaccess to pass the requested filename into a querystring variable, like route in my question above, in PHP there are some server variables that can be used. So, I changed my logic in index.php from reading the querystring to:

trim( $_SERVER['REDIRECT_URL'], "/" );

在REDIRECT_URL(和REQUEST_URI)服务器变量将保留圆点和装饰将得到的开头和结尾的斜杠关,类似与重写规则会发生什么。

The REDIRECT_URL (and REQUEST_URI) server variables will retain the trailing dots, and the trim will get the leading and trailing slashes off, similar to what happens with the rewrite rule.

这篇关于URL重写结束时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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