2016-07-15 06:27
浏览 238


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]

Can someone tell me what is the issue here?

图片转代码服务由CSDN问答提供 功能建议

在我的应用程序中,我的域名指向index.php。 我有一个名为“mod”的文件夹,我想将所有请求从“mod”文件夹重定向到index.php

这是我在启用网站的conf文件中的规则但是 它不起作用,意味着我仍然可以从url

 &lt; IfModule mod_rewrite.c&gt; 
 RewriteEngine On 
 RewriteBase /访问mod文件夹中的文件 
 RewriteRule ^ mod /.* http://domain.com/ [R = 301,L] 
&lt; / IfModule&gt; 

有人能告诉我 这是什么问题?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.


    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]
    点赞 打赏 评论

相关推荐 更多相似问题