mod-rewrite问题? [英] mod rewrite problem?

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

问题描述

我想改写这个网址:

http://www.example.com/user.php?user=username

http://example.com/username

我用我的.htaccess这个code:

I'm using this code in my .htaccess:

RewriteEngine On
RewriteRule ^([^/]*)$ /user.php?user=$1 [L]

但它给了我一个内部错误。是不是有什么不对吗?

but its giving me an internal error. Is there something wrong?

推荐答案

要匹配的URL的查询字符串的一部分,你必须使用的RewriteCond,像这样的:

To match the query string part of a URL, you have to use RewriteCond, like this:

RewriteEngine On
RewriteCond %{QUERY_STRING} user=(.*)
RewriteRule ^user.php$ %1 [L]

因此​​,用户名中的RewriteCond规则匹配?用户=名称,然后%1使用在我的例子中的最后一行所产生的改写该值。

So the RewriteCond rule matches the username in ?user=name and then the %1 uses that value in the resulting rewrite on the last line of my example.

在斜线问题,就像/名称的URL都会自动重定向到喜欢的网址/名/如果Web服务器发现/名称是一个目录。所以,如果你的目的是要映射user.php的/用户=名称类似于/name/index.html,你就会导致得到插入斜线。但是,如果你的目的是将其映射到一个文件(或CGI脚本)在/名称,然后它会正常工作。

On the slash issue, URLs like /name get automatically redirected to URLs like /name/ if the web server finds that /name is a directory. So if your intention is to map user.php/user=name to something like /name/index.html, you will cause that slash to get inserted. But if your intention is to map it to a file (or CGI script) at /name then it will work as expected.

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

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