htaccess的问题 - URL重写 [英] .htaccess question - URL-rewriting

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

问题描述

我有一个问题,在.htaccess URL重写。下面是.htaccess文件:

I have an issue with URL-rewriting in .htaccess. Here is .htaccess file:

RewriteEngine On
RewriteBase /community/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^view-all-results$ forums/index.php?view=view-all-results [R=302]
RewriteRule ^view-all-results/$ forums/index.php?view=view-all-results [R=302]

我需要重写URL如 /社区/视图所有结果?U = 2 社区/论坛/指数。 PHP的视图=视图,所有的结果和放大器; U = 2 。 但是,根据上述规则,我会得到社区/论坛/的index.php?认为=视图,所有结果

I need to rewrite url like "/community/view-all-results?u=2" to "community/forums/index.php?view=view-all-results&u=2". But according to the above rule I'll get "community/forums/index.php?view=view-all-results".

我试图改变重写规则,以

I tried to change RewriteRule to

RewriteRule ^view-all-results?(.*)$ forums/index.php?view=view-all-results&$1 [R=302]

但它不能正常工作。它仍然重写URL以社区/论坛/的index.php?认为=视图,所有结果

当我改变规则(放+,而不是*):

When I changed rule(put + instead of *):

RewriteRule ^view-all-results?(.+)$ forums/index.php?view=view-all-results&$1 [R=302]

我有喜欢的网址社区/论坛/ index.php的视图=视图,所有的结果和放大器;·S 。所以,我不理解这种行为。((

I've got URL like "community/forums/index.php?view=view-all-results&s". So I don't understand this behavior.((

我会pciated的任何建议非常AP $ P $。

I will be very appreciated for any suggestions.

推荐答案

神奇标志的在docs: [QSA] ,这将增加原有的查询字符串为您的网址

The magic flag is in the docs: [QSA], which will add the original querystring to your url.

标准匹配只对路径进行,而不是agains的querysting,你会发现在魔术变量%{QUERY_STRING} )。匹配这个变量可以在的RewriteCond 的条件来完成。您还可以追加此变量产生的URL,但 QSA 是无限多userfriendely这里。

Normal matching is only done against the path, not agains the querysting, which you would find in the magic variable %{QUERY_STRING}). Matching this variable can be done in a RewriteCond condition. You could also append this variable to the resulting url, but QSA is infinitely more userfriendely here.

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

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