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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试