【问题标题】:Rewrite all links to index.php with multiple slashes用多个斜杠重写所有指向 index.php 的链接
【发布时间】:2014-12-25 05:03:59
【问题描述】:

我在互联网上搜索了我的问题的解决方案,但找不到。所以我想重定向(RewriteRule)所有指向 index.php 的链接,例如: 本地主机,本地主机/x,本地主机/x-y,本地主机/x-y/z

我阅读了它和我的 .htaccess 文件:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L]

问题出在哪里?我的 CSS 文件有问题,它位于 include/css/style.css 中。当链接是这样的: localhost 或 localhost/x 一切都很好,但是当我添加更多斜杠文件时不会加载。

这部分的HTML:

<link href="./includes/css/basicstyle.css" type="text/CSS" rel="Stylesheet">

我知道这个问题对很多人来说很容易,但我尝试了 2 天,但我没有任何进展。

问候

【问题讨论】:

    标签: php html css .htaccess mod-rewrite


    【解决方案1】:

    这就是wordpress正在使用的......

    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]  
    RewriteRule ^(.*\.php)$ $1 [L]  
    RewriteRule . index.php [L]
    

    也许这会有所帮助?

    RewriteRule ^(includes).*) $1 [L]
    RewriteRule ^(.*\.php|.*\.css|.*\.js)$ $1 [L]
    RewriteRule . index.php [L]
    

    但我不得不说,我没有太多的 mod 重写经验,但希望它会有所帮助:)

    【讨论】:

    • 非常感谢 Mephiztopheles :) 您的代码工作需要将 ./includes 替换为 /includes,但它正在工作。非常感谢你一次:)
    • nice :) 总是乐于提供帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多