【问题标题】:Can't get forward slash .htaccess redirect to work无法获得正斜杠 .htaccess 重定向工作
【发布时间】:2020-05-12 18:59:03
【问题描述】:

我正在尝试执行以下重定向,但无法使其正常工作,感谢任何帮助:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^service-pricing$ index.php?rp=/service/pricing/ [NC]

以上只是导致页面找不到。

【问题讨论】:

  • 您要测试的 URL 是什么?你有index.php 文件吗?
  • 我正在尝试将 URL 从 www.domain.com/index.php?rp=/service/pricing/ 重写为以下内容:www.domain.com/service-pricing
  • 如果你想朝那个方向重写,你可能需要一种不同的方法。请参阅Rewrite to “pretty URL”PHP .htaccess -> pretty url (in reverse)
  • @Linuc82 您通常不会朝那个方向重写(如您的评论中所述)? (可能重定向;不重写)。您的问题中的指令实际上“看起来不错”,前提是您请求的是 URL /service-pricing。如果您不使用“正斜杠”(您的问题的措辞方式暗示它确实如此),它是否“有效”?您能否确认接受此请求的文件的完整 URL 路径(即index.php)和此.htaccess 文件的位置?这个.htaccess 文件中还有其他指令吗? .htaccess 文件是否启用?

标签: apache .htaccess


【解决方案1】:

你错过了重写的工作原理。规则会以某种方式神奇地转换您发送的引用。相反,它们会在 incoming 请求中得到应用。

以下是应该为您指明正确方向的方法:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^rp=/service/pricing/?$
RewriteRule ^/?index\.php$ /service-pricing [END]

您绝对应该开始阅读您使用的工具的文档。作为开源项目的典型代表,它具有卓越的品质并带有很好的示例:https://httpd.apache.org/docs/current/mod/mod_rewrite.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2015-06-19
    • 2016-10-29
    • 1970-01-01
    • 2015-07-23
    • 2012-12-10
    • 1970-01-01
    相关资源
    最近更新 更多