Skip to content
Advertisement

.htaccess redirect but exclude some folder

Hello there I am using cpanel. In the cpanel, I created a redirect, which created an .htaccess like this.

JavaScript

The problem with this, when I added new folder my public directory and view my page, it will always redirect to the ‘mainfolder’. How will I add a RewriteCond that will not redirect to the main folder if my link is something like http://paw.xevz.migor.eu/subfolder ? I tried like this,

JavaScript

but no luck. Please help thank you.

P.S. Those links in my .htaccess are just sample.

Advertisement

Answer

RewriteRule ^/?$ will only match and redirect landing page URI. You may have a front controller rule in the end that rewrites everything to something like ?page=something and that would trigger this redirect rule for all the URIs that are not for a file or directory.

You may use this redirect rule instead:

JavaScript

Make sure this is your topmost rules below RewriteEngine On line and you test it after clearing your browser cache.

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

RewriteCond %{ENV:REDIRECT_STATUS} ^$ will make sure this rule is not executed after 1 or more rewrites due to other rules.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement