douren9077
2016-02-10 22:29
浏览 53
已采纳

重定向错误(.htaccess)

I am trying to use .htaccess file for my REST service but I found that the url are not actually redirected. The web server show

Error Message

I wanted to use url such as

/api/v1/test

instead of

/api/v1/rest.php?request=test

I have already check mod_rewrite is acutally working.

My .htaccess file is as below

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/rest.php?request=$1 [QSA,NC,L]

I have already look at PHP redirecting problem and Sitemap redirecting

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将.htaccess文件用于我的REST服务,但我发现该url实际上并未重定向。 网络服务器显示

我想使用网址,例如 \ n

  / api / v1 / test 
   
 
 

而不是

  / api / v1  /rest.php?request=test
nn

我已经检查 mod_rewrite 正在工作。

我的 .htaccess 文件如下所示

  RewriteEngine On 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond  %{REQUEST_FILENAME}!-d 
RewriteRule api / v1 /(.*)$ api / v1 / rest.php?request = $ 1 [QSA,NC,L] 
   
 
  

我已经看过 PHP重定向问题网站地图重定向

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • download1002 2016-02-10 22:34
    已采纳

    you can try this rule instead because it works with me :

    RewriteRule    api/v1/([A-Za-z0-9-]+)/?$    api/v1/rest.php?request=$1
    

    try putting .htaccess file in htdocs directory and if the directory api location is

    C:\xampp\htdcos\xampp\www\api
    

    then put the full path in the rule

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题