【问题标题】:htaccess files redirects images and css filehtaccess 文件重定向图像和 css 文件
【发布时间】:2012-01-22 22:05:54
【问题描述】:

我正在使用 .htacess 文件通过此脚本重定向我的页面:

*#domain/page/about 
RewriteRule ^page/(.*)/(.*)?$  detail.php?tag=$1 [NC]
RewriteRule ^page/(.*)?$  detail.php?tag=$1 [NC]*

#domain/about 
RewriteRule ^(.*)?$  detail.php?tag=$1 [NC] 

脚本运行良好,但当我使用时:

#domain/about 
RewriteRule ^(.*)?$  detail.php?tag=$1 [NC]

我所有的图片、jscripts 和 css 文件都被禁用了。

我知道这是由于上面的脚本,但我可以告诉 .htaccess 文件忽略重定向的 .css、.jpg 文件或将它们放在原处吗?

【问题讨论】:

    标签: css image .htaccess redirect


    【解决方案1】:

    在你的 RewriteRule 之前添加这一行:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?!index\.php/?)(.*)$  detail.php?tag=$1 [NC,QSA,L]
    

    此行将阻止 css、js 和图像文件的重定向。

    还记得在你的 RewriteRule 中添加 L 标志以将其标记为 Last 规则。

    【讨论】:

    • 感谢它的工作,但现在我的索引文件也重定向到 detail.php。
    • 好吧,index.php 重定向的问题甚至在我提出建议之前就已经存在。但是请尝试在我的答案中更新代码。
    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2021-06-29
    • 1970-01-01
    相关资源
    最近更新 更多