cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect all pages to homepage via .htaccess except backend

Redirect all pages to homepage via .htaccess except backend

Hi there!

 

I've been trying to redirect all pages of my Magento website to homepage via .htaccess - except the backend, naturally. Currently, I'm using these rules and everything is working fine so far but I want to access my backend (domain.com/office):

 

# Redirect the all pages to homepage

RewriteEngine On
RewriteCond %{REQUEST_URI} !/$ [NC]
RewriteCond %{REQUEST_URI} !.(css|fonts|gif|jpe?g?|png|ico) [NC]
RewriteRule ^(.*)$ / [R=302,L]

 

Can someone help me with this? I've been trying many rules but none of them worked well. With some rules, when I try to access my backend, I'm still redirected to homepage. With other rules, I got a ERR_TOO_MANY_REDIRECTS error message.

Thanks!

1 REPLY 1

Re: Redirect all pages to homepage via .htaccess except backend

Hey @josh_smith2 

Try once following rule:

 RewriteEngine On
    RewriteBase /

    # Testing if `admin` then if so, stop rewrite rules, you can change here you admin path
    RewriteRule (.*)/office(.*) - [QSA,L,NC]

    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteCond %{REQUEST_FILENAME}/index.php !-f
    RewriteRule . index.php [L]

OR Modified your code:

# Redirect the all pages to homepage

RewriteEngine On
RewriteCond %{REQUEST_URI} !/$ [NC]
RewriteCond %{REQUEST_URI} !.(css|fonts|gif|jpe?g?|png|ico) [NC]
RewriteRule ^(.*)$ / [R=302,L]
RewriteRule !^office / [L,NC,R=302]