【问题标题】:Rewrite everything to index.php?将所有内容重写为 index.php?
【发布时间】:2016-11-23 11:33:50
【问题描述】:

这是一个快速的问题。如何更改 .htaccess 文件以重写所有内容以将其重定向到 index.php 文件?

当我删除RewriteCond 的行时,我会得到一个505 Internal Server Error。

这是我的.htaccess 文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting http-status-code-505


    【解决方案1】:

    你可以使用这条规则:

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ [NC]
    RewriteRule !^index\.php$ index.php [L,NC]
    
    • RewriteCond 将跳过对 image/css/js 文件的重写。
    • 否定表达式!^index\.php$ 表示匹配除index.php 之外的任何内容。

    【讨论】:

    • 这是否也会以某种方式重定向图像?因为我只想重写非图像文件。
    • 检查我更新的答案以忽略 css/js/image 文件。
    猜你喜欢
    • 1970-01-01
    • 2013-12-31
    • 2012-07-22
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    相关资源
    最近更新 更多