【问题标题】:.htaccess redirect URL with loaded css, js and image.htaccess 带有加载的 css、js 和图像的重定向 URL
【发布时间】:2017-10-27 05:18:36
【问题描述】:

我正在尝试从 .htaccess 文件中重写 URL,尝试了很多但以失败告终。

.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond    ^suba/?$    resources/uploads/releases/zipfiles/1484883480/index\.html [NC, C]
        RewriteRule ^ index.php [L]

我只想用这样的短 URL 打开this,以使其对 SEO 更友好,
http://dittmagasin.no/release

我参考了以下帖子:

  1. URL rewriting with PHP
  2. URL rewriting for beginners

任何帮助将不胜感激。 谢谢

【问题讨论】:

    标签: apache laravel .htaccess mod-rewrite


    【解决方案1】:

    你可以使用:

    RewriteEngine On
    
    RewriteRule ^release/?$ resources/uploads/releases/zipfiles/1484883480/index.html [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    【讨论】:

    • dittmagasin.no/release,不加载 CSS、JS 和图像。你能帮我解决这个问题吗?
    • 这是因为你的 css/js/image 中的相对路径。您需要将其添加到页面 HTML 的 &lt;head&gt; 部分下方:&lt;base href="/resources/uploads/releases/zipfiles/1484883480/" /&gt;
    • 正如我之前提到的,问题在于您使用相对路径。重写规则部分完成。如何告诉浏览器查找 css/js/images 取决于您。有两种解决方案:您可以提供以/ 开头的完整路径,也可以按照我的建议使用base 标签。
    • 非常感谢。我会尝试
    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 2012-10-04
    • 1970-01-01
    • 2016-11-07
    • 2016-03-31
    • 2022-12-29
    • 2015-01-22
    • 2018-06-29
    相关资源
    最近更新 更多