请帮助解决这个mod_rewrite问题

时间:2011-08-22 16:08:32

标签: apache mod-rewrite apache2

这个当前系统需要允许句点(.)可选地在重写条件内。

例如:/john.doe应该有效,因为我们在用户名中允许使用句点。

但是,当我将.\\.[.]添加到以下重写规则时,它会陷入无限循环,必须重新启动apache2。令人惊讶的是,行为发生了变化,我不知道为什么。现在它只是将新字符串附加到现有URL。

例如:/john.doe将成为/john.doe/?pg=user&username=john.doe

RewriteRule ^/([a-z0-9_]+)$ /?pg=user&username=$1 [NC,PT]

我很想解决这个问题,请帮忙!

1 个答案:

答案 0 :(得分:0)

这应该有用(我说“应该”因为我不知道你的整个系统是如何设置的以及其他重定向等等 - 我看到你正在使用PT标志(也许你正在使用别名)):

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^([a-z0-9_\.]+)$ /index.php?pg=user&username=$1 [NC,QSA,L]

OR

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z0-9_\.]+)$ /index.php?pg=user&username=$1 [NC,QSA,L]

我已经直接指定了脚本文件 - 如果您知道它如何工作,编写规则要容易得多。

相关问题