url重写给出“找不到对象".错误 [英] url rewriting gives "object not found" error

查看:88
本文介绍了url重写给出“找不到对象".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的原始网址

http://localhost/mysite/mainarticle?article_id=84

RewriteRule

RewriteRule

RewriteRule ^/article/([0-9]+) /mainarticle?article_id=$1 [L]

新网址

http://localhost/mysite/article/84

当我使用new url时,会出现Object not found错误.似乎我的重写规则不起作用.如果我正确使用规则或需要更改,请寻求您的帮助.

When I use the new url it gives the Object not found error. Seems like my rewrite rule is not working. Need your help if I'm using the rule correctly or changes are needed.

注意:

我也在使用其他规则来隐藏扩展名.

I'm using additional rules as well to hide extentions.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

推荐答案

您正在使用绝对路径,但是/mysite/不是文档的根目录,因此无法使用.删除斜杠以使用相对路径,您应该会很好.

You are using absolute paths, but /mysite/ isn't the document root, so that won't work. Remove the leading slashes to use relative paths and you should be good.

RewriteRule ^article/([0-9]+) mainarticle?article_id=$1 [L]

由于这是内部重定向,因此您也可以安全地添加.php扩展名,以防万一您知道要定位的文件,这样可以避免对丢失的扩展名进行额外的重写.

As it's an internal redirect you can also safely add the .php extension in case you know that's the file you are targeting, this would avoid an additional rewrite for the missing extension.

... mainarticle.php?article_id=$1 [L]

这篇关于url重写给出“找不到对象".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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