【问题标题】:URL Rewrite keeps returning 404 ErrorURL 重写不断返回 404 错误
【发布时间】:2014-06-27 15:00:27
【问题描述】:

我为 URL 重写创建了一个 .htaccess 文件,我使用 http://htaccess.madewithlove.be/ 对其进行了测试,它说 URL 重写是正确的,但是在测试页面时一直给我一个 404 错误。

这是.htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/(.*)$ /article/index.php?id=$1 

我需要的 URL 重写如下:

http://www.mydomain.com/article/test  // To redirect to: 
http://www.mydomain.com/article/index.php?k=test

谁能告诉我我在搞砸什么? 谢谢!

【问题讨论】:

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


    【解决方案1】:

    首先,确保存在一个名为 /article/index.php 的文件,然后试一试:

    RewriteEngine On
    RewriteBase /
    # Condition: the requested file is non-existent
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^article/(.*)$ /article/index.php?id=$1 [L,R=301]
    

    【讨论】:

    • 救命稻草!太感谢了!只是为了记录,你能向我解释一下出了什么问题吗? (当我收到错误时,该文件确实存在。)
    • 好的,我的客户端服务器现在返回 404,但重写工作正常。如果我必须进行以下重写,我应该改变什么:`mydomain.com/articles/article/test``mydomain.com/articles/article/index.php?k=test`对不起这些愚蠢的问题,但我之前没有使用过.htaccess文件,我不知道如何调试。
    猜你喜欢
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 2013-05-31
    • 2013-08-13
    相关资源
    最近更新 更多