【问题标题】:htaccess rewrite returns 404 not foundhtaccess 重写返回 404 未找到
【发布时间】:2014-01-21 03:21:38
【问题描述】:

我想要这样,如果用户输入 webaddress.com/artist/P1/P2/,它会使用 /artist/index.php?artist=P1&am=P2

P1 是艺术家的名字,所以它可以包含字母和数字。 P2 将是一个数字,所以只是数字。

我想要它以便 P1 是必不可少的,而 P2 不是因为现在它只返回 404 not found on that address。当前代码:

RewriteEngine on
RewriteRule ^artist/([^/]+)/(\d+)/$ /artist/index.php?artist=$1&am=$2 [L]

【问题讨论】:

  • 您检查过实际返回 404 的内容吗?可能是因为您的脚本上没有 /artist/index.php... 或者该脚本实际上正在运行,但由于艺术家/am 参数不正确而发出了自己的 404。
  • 脚本存在,它似乎没有将我引导到任何地方,因为它会立即加载。您能否告诉我我提供的代码是否有任何问题?
  • 好吧,在 index.php 脚本的顶部填充一个die('Yoohoo!') 或其他内容。如果你明白了,那么你的重写至少指向正确的脚本,你应该检查var_dump($_GET),看看你的参数是否正常。如果你没有得到 yoohoo 输出,那么重写有问题
  • 是的,但它是在 .htaccess 文件中,还是在 httpd.conf 中?如果在conf中,是在<VirtualHost>,还是<Directory>
  • 您的错误日志对 404 有什么看法?

标签: php .htaccess rewrite


【解决方案1】:

/artist/index.php 表示服务器调用 /artist/ 上有一个根目录。我以某种方式怀疑这一点(它确实存在,它不应该)。

删除艺术家之前的前导/,看看是否有效。

RewriteEngine on
RewriteRule ^artist/([^/]+)/(\d+)/$ artist/index.php?artist=$1&am=$2 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多