duanfoumi5620 2016-07-15 06:27
浏览 305
已采纳

Apache重定向到另一个文件夹

In my application I have my domain pointing to the index.php. I have a folder called "mod" and I want to redirect all the request from the "mod" folder to the index.php

Here is my rule in the sites-enabled conf file but it is not working, means I'm still able to access the files in the mod folder from url

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^mod/.* http://domain.com/ [R=301,L]
</IfModule>

Can someone tell me what is the issue here?

  • 写回答

1条回答 默认 最新

  • doubi7739 2016-07-15 06:32
    关注

    Have your rule like this:

    RewriteEngine On
    
    RewriteRule ^/?mod/ /index.php [L]
    

    Note optional leading slash before mod which will make this rule work in .htaccess as well in Apache config files. Also I removed R to avoid external redirect.

    Edit:

    Seems there is problem with ajax requests. So we need to differentiate the ajax requests by sending ajax=1 for ajax requests and change the rule.

    Create a .htaccess file in mod folder and add these lines

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} !(^|&)ajax= [NC]
    RewriteRule ^ /index.php [L,R]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度