【问题标题】:can not load css and js after htaccess redirect url in phpphp中htaccess重定向url后无法加载css和js
【发布时间】:2016-08-25 19:25:15
【问题描述】:

我使用 htaccess 重定向我的 url,并在 .htaccess 文件中使用此代码

RewriteEngine On
RewriteRule ^mobile?$ index.php
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^product/([0-9]+)/(.*)$ product.php?c=$1&title=$2 [QSA,L]

and also add this code in product.php 
<head> <base href="http://localhost/asp/" /> </head>

product.php 文件中的代码。我重定向成功,但无法以正确的方式加载 css 和 js。任何人都可以向我建议如何在 product.php 页面上加载 css 和 js。我可以成功加载图像但页面设计无法正常工作。我搜索了很多但没有得到正确的答案请任何人都可以提供方法或对我有帮助的代码。

【问题讨论】:

  • @starkeen 这对我不起作用,你能给我任何建议吗
  • 为您的 css、js 和图像使用绝对路径,例如 /style.css 而不是 style.css
  • @starkeen 我已经这样做了,但我不知道为什么不工作
  • 您的 css、js 和图片加载情况如何?你能看看你网页的来源吗?

标签: javascript php css .htaccess mod-rewrite


【解决方案1】:

如您所知,base 的默认行为是替换相对地址之前的 url(adress)。 示例:

&lt;base href="http://www.mywebsite.com/images/" target="_blank"&gt;

浏览器会在“http://www.mywebsite.com/images/html5.gif”处寻找图片“html5.png”。

希望对你有帮助!

【讨论】:

    【解决方案2】:

    创建一个主文件夹,然后将所有文件放在这样的文件夹中enter image description here ...

    【讨论】:

    • 可以使用include方法吗?
    猜你喜欢
    • 2017-10-27
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 2012-01-03
    • 2020-01-15
    相关资源
    最近更新 更多