0

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!

2 Answers 2

1

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...
1
  • Thank you so much, Christoph! I just changed a little bit your last line and it's working perfectly now for me.
    – Josh Smith
    Commented Jul 3, 2019 at 10:56
1

Try this

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/office/
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
1
  • Thank you for your reply, Abdul. However, I got a 500 - Internal Server Error...
    – Josh Smith
    Commented Jul 2, 2019 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.