url rewriting gives “object not found” error

好久不见. 提交于 2020-01-06 13:41:47

问题


Below is my original url

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

RewriteRule

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

new url

http://localhost/mysite/article/84

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.

Note:

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

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

回答1:


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]

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]


来源:https://stackoverflow.com/questions/23554802/url-rewriting-gives-object-not-found-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!