Question

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!

Was it helpful?

Solution

Create a .htaccess file containing only this should work (backup the original one):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/office
RewriteCond %{REQUEST_URI} !^/index.php/office
RewriteCond %{REQUEST_URI} !^/$ 
RewriteCond %{REQUEST_URI} !.(css|fonts|gif|jpe?g?|png|ico|js) [NC]
RewriteRule (.*) http://domain.com/ [R=302]

roughly translates to:

  • enable rewriting possibilities
  • line 2: apply rewrite rule from line 6 if path is NOT /admin
  • line 3: apply rewrite rule from line 6 if path is NOT /index.php/office (since you'll probably be redirected from /office to /index.php/office/...)
  • line 4: apply rewrite rule from line 6 if path is NOT / (= homepage)
  • line 5: if requested file ending is not one of ...
  • line 6: definitely make it a 302 or else your customers might still go in circles once you revert back to the original .htaccess file...

OTHER TIPS

Try this

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/office/
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top