【问题标题】:How to transform an url to other?如何将网址转换为其他网址?
【发布时间】:2015-09-17 10:04:21
【问题描述】:

我需要转换这个网址的:

  • localhost:8080/codeschoolangular/codeschoolangular/ApiRest/users/1
  • localhost:8080/codeschoolangular/codeschoolangular/ApiRest/users

  • localhost:8080/codeschoolangular/codeschoolangular/ApiRest/api2.php?rquest=users&id=$1
  • localhost:8080/codeschoolangular/codeschoolangular/ApiRest/api2.php?rquest=users

在同一个 .htacces 中

我试试:

RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME} !-s

RewriteRule  ^([A-Za-z]+)/?$ /codeschoolangular/codeschoolangular/ApiRest/api2.php?rquest=$1 [QSA,NC,L]

RewriteRule "^users/([0-9]+)/$" /codeschoolangular/codeschoolangular/ApiRest/api2.php?rquest=users&id=$1 [QSA,NC,L]

但不工作。

谁能帮忙解决这个问题?

提前致谢。

【问题讨论】:

  • 我猜你实际上并没有包括“#”,对吧?
  • 在所有重写规则之前添加一个RewriteEngine on之前。此外,您必须在 http 服务器配置中完全考虑 .htaccess 样式文件。然后发出请求并检查日志文件是否有错误。
  • jejeje 对,没有# 不工作。
  • @arkascha ,我有这一切,但不工作。谢谢。
  • .htaccess 包括位于您的目录层次结构中的指令在哪里?

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

你错过了“?”在第二条规则中的“/”之后。试试这个:

RewriteRule "^users/([0-9]+)/?$" /codeschoolangular/codeschoolangular/ApiRest/api2.php?rquest=users&id=$1 [QSA,NC,L]

【讨论】:

    猜你喜欢
    • 2015-04-30
    • 2020-10-19
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    相关资源
    最近更新 更多