ling.s ling.s - 1 year ago 103
PHP Question

Apache redirect to another folder

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/.* [R=301,L]

Can someone tell me what is the issue here?

Answer Source

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.


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

RewriteEngine On
RewriteRule ^ /index.php [L,R]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download