【问题标题】:htaccess rewrite rule not loading site contenthtaccess 重写规则不加载网站内容
【发布时间】:2010-11-19 10:16:53
【问题描述】:

我正在为 .htaccess 重写规则而苦苦挣扎。 假设我有这个 URL。

localhost/site/index.php

我想把它改写成这个网址

localhost/site/tutorial

我会使用这个 RewriteRule

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^tutorial/(.*)$ /up/index.php

页面可以正常工作,但 CSS 文件无法加载。

另外,如果我有这样的网址:

index.php?page=home

然后我将不得不解析该 URL 以获取不再使用 $_GET 的“家”正确吗??

【问题讨论】:

  • 郑重声明,语法并没有过时。
  • 你的css文件在哪里?你为什么期望它与这样的RewriteRule 一起工作?

标签: apache .htaccess mod-rewrite


【解决方案1】:

只需为您的 CSS 文件使用绝对 URL,或至少从域根目录引用。

http://www.mysite.com/css/myCssFile.css

/css/myCssFile.css

【讨论】:

    【解决方案2】:

    因此 CSS 文件未加载,因为您正在更改所服务文件的位置。

    因此,如果您链​​接到 ./css/style.css => ^/tutorial/css/style.css 与 /up/css/style.css 不同

    如果你重写,你可以保留get:

    RewriteRule ^tutorial/(.*)?(.*)$ /up/index.php?$2
    

    【讨论】:

      【解决方案3】:
      Options +FollowSymLinks
      RewriteEngine on
      
      RewriteRule ^tutorial/(.*)$ /up/index.php
      

      这会将进入教程目录的所有内容重写为/up/index.php,这意味着除非您将 CSS 文件托管在该位置,否则它将无法工作。如果您的 css 文件位于 /tutorial/css.css,它将重定向到 /up/index.php

      您必须解析 %QUERYSTRING% 才能根据 index.php?page=home 进行重定向

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-01
        • 1970-01-01
        • 2013-12-20
        • 1970-01-01
        • 1970-01-01
        • 2015-12-27
        • 2011-11-03
        相关资源
        最近更新 更多