php - .htaccess css 和图像文件重定向

标签 php apache .htaccess redirect

我想这样做,如果请求 /css/images 路径...它会重定向到 /images 目录root 但对于所有其他我希望它指向 pages 目录。

我得到了第二部分的工作......这将全部重定向到页面目录

RewriteEngine on
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]

但如果用户请求 /css/images 我无法让第一部分工作,它会转到默认文件夹而不是 /pages 在路径中。

我的文件夹结构:

css
    css files
images
    image files
pages
    index.php
    about
        index.php

最佳答案

你可以添加一个 RewriteCondition 来防止这种情况

RewriteEngine on

RewriteCond %{REQUEST_URI} !\.(css|png|gif|jpg)$
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]

关于php - .htaccess css 和图像文件重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48357566/

相关文章:

PHP报错问题

java - org.apache.commons.net.ftp 使用不同的端口

apache - 允许 paypal ipn 绕过 .htaccess 中的 Basic Auth

reactjs - 使用代理时,React 应用程序正在不同位置查找静态文件

.htaccess - htaccess 在多个 404 重定向上发送 404 状态

php - 建立一个 rss 提要

php - 在 PHP 中比较字符串时忽略大小写敏感

php - CodeIgniter 仅显示默认 Controller

.htaccess - mod_rewrite URLs

php - Mysql中的 block 时区转换: compare the orginal time or date value(which the user gave) to database values