【问题标题】:.htaccess css and image files redirection.htaccess css 和图像文件重定向
【发布时间】:2018-06-29 15:59:54
【问题描述】:

我想这样做,如果请求/css/images 路径...它会从root 重定向到/images 目录,但对于所有其他人,我希望它指向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

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:

    您可以添加一个 RewriteCondition 来防止这种情况发生

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

    【讨论】:

      【解决方案2】:

      这个怎么样?

      RewriteEngine on
      
      RewriteCond %{REQUEST_URI} "^/css" [OR]  # if user access "/css" path
      RewriteCond %{REQUEST_URI} "^/images"    # or "/images" path
      RewriteRule (.*) "/images/$1" [L]        # then redirect to "/images"
      
      RewriteRule (.*) "/pages/$1" [L]         # otherwise redirect to "/pages"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-11
        • 1970-01-01
        • 2011-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多