【问题标题】:How to fix mod_rewrite problem with static to dynamic content如何修复静态到动态内容的 mod_rewrite 问题
【发布时间】:2021-08-15 03:50:23
【问题描述】:

如果有人可以帮助解决这个 mod 重写问题,我将不胜感激。多年来,我在我的 htaccess、apache 包含文件中都有这个,它工作得很好。

RewriteRule ^/article/([0-9]*).html$ /article/article.php?id=$1 [NC,L]

但最近它停止工作了。浏览器显示“未指定输入文件”。并且访问日志会显示 404 响应代码,即上述条件必须满足的请求。

重写引擎已打开。这就是我目前的 htaccess mod_rewrite 规则

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php     [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^/article/([0-9]*).html$ /article/article.php?id=$1 [NC,L]
RewriteRule ^/relationships/([0-9]*).html$ /article/article.php?id=$1 [NC,L]
</IfModule>

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    对于您显示的示例/尝试,您能否尝试遵循 htaccess 规则。请确保在测试 URL 之前将您的 htaccess 规则文件放在根目录下并清除浏览器缓存。

    <IfModule mod_rewrite.c>
    Options -MultiViews -Indexes
    RewriteEngine On
    RewriteBase /
    
    ##Rules for non-existing pages.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    
    ##Rules for articile and relationship uris here.
    RewriteRule ^(?:article|relationships)/([0-9]*)\.html/?$ article/article.php?id=$1 [NC,L]
    
    ##Rules for 404 handling.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) 404error.php  [L,NC]
    
    </IfModule>
    

    【讨论】:

    • 非常感谢。它仍然返回一个 404 状态代码,并且消息是相同的“未指定输入文件”。
    • @virap,你能告诉我你在这里点击的示例网址是什么吗?
    • 确认 .htaccess 和 /article/ 在同一级别
    • 谢谢。是的,添加-------会导致“内部服务器错误”
    猜你喜欢
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 2013-04-29
    • 2014-01-25
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    相关资源
    最近更新 更多