【问题标题】:Apache RewriteRule mode not workingApache RewriteRule 模式不起作用
【发布时间】:2015-07-22 09:29:58
【问题描述】:

我想重写规则以允许这样的路径:

http://example.com/api/somemethod/ api是一个api.php文件,包含api类。

我已经在 .htaccess 中重写了规则,但是如果我尝试在上面链接,我得到一个错误:

Object not found! The requested URL was not found on this server. If
you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404

这是我的 .htaccess 文件:

重写引擎开启

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?x=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    由于我还不能对这个问题发表评论 (yay karma),我将发布一个更常见的答案,因为这通常是由于 .htaccess 文件未被读取/关注造成的:

    "尝试将垃圾放入您的 htaccess 文件中。如果它正在被读取,您将 访问该资源时出现内部服务器错误。如果它 不会导致内部服务器错误,请参阅 AllowOverride。这不会 如果 AllowOverride 与 Nonfatal 一起使用,则从 2.4 开始工作"

    【讨论】:

    • Thaks,但我怎样才能摆脱错误?我该怎么办?
    • 如果您的 htaccess 文件没有被读取,您必须编辑您的主配置并使用AllowOverride FileInfo 在 htaccess 文件中启用 mod_rewrite。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2014-09-03
    相关资源
    最近更新 更多