【问题标题】:Redirect URL as well as Change Query String Apache重定向 URL 以及更改查询字符串 Apache
【发布时间】:2016-12-31 12:45:32
【问题描述】:

我有两个条件:

http://localhost/restexample/api/con/2/

重写为

http://localhost/restexample/RestController.php?phone=single&id=2

http://localhost/restexample/api?number=12345

重定向/重写到

http://localhost/restexample/RestController.php?phone=all&no=12345

我在第一种情况下得到了正确的响应,但在第二种情况下没有。

我的 .htaccess 文件是:

# Turn rewrite engine on
Options +FollowSymlinks
RewriteEngine on

# map neat URL to internal URL
RewriteRule api/con/([0-9]+)/$   "RestController.php?phone=single&id=$1" [nc,qsa]

RewriteCond %{QUERY_STRING} number=(\d+)$     
RewriteRule "^api"  "RestController.php?phone=all&no=%1" [nc,qsa,R=301]

请有人帮忙。

第二个文件的输出:

【问题讨论】:

    标签: php apache .htaccess mod-rewrite localhost


    【解决方案1】:

    试试这些规则:

    Options +FollowSymlinks
    RewriteEngine on
    
    # map neat URL to internal URL
    RewriteRule ^api/con/([0-9]+)/?$ RestController.php?phone=single&id=$1 [NC,L,QSA]
    
    RewriteCond %{QUERY_STRING} (?:^|&)number=(\d+)$
    RewriteRule ^api/?$ RestController.php?phone=all&no=%1 [NC,L]
    

    【讨论】:

    • 403 错误。它位于 xampp/htdocs/restexample。见图片。地址栏中的地址。
    • 图片中显示的网址是http://localhost/restexample/12345,但此规则适用于http://localhost/restexample/api?number=1234‌​5
    • 对不起,这是调用 localhost/restexample/api?number=12345 的结果。它实际上应该转到 localhost/restexample/RestController.php 但地址栏中的上述 url 出现错误 403
    • 我明天试试。目前,我在家,代码在办公室电脑上。谢谢你的指导:)
    • 谢谢哥们!!它今天正在工作。所以也许浏览器缓存一定是你说的问题。抱歉回复晚了。你会很高兴解释我在哪里做错了!再次感谢! :)
    猜你喜欢
    • 2017-04-21
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 2014-11-03
    相关资源
    最近更新 更多