Post by dither » Sat Feb 02, 2013 9:38 pm

I have problem implementing SEO and password protecting the admin folder simultaneously.

What I did:
- I have enabled SEO in backend and renamed the .htaccess file and it worked fine.
- My opencart installation is not in a subdirectory so i didn't have to alter RewriteBase /.
- Then, I've placed another .htaccess file inside the admin folder for password protecting it with basic authentication.

What happened:
- SEO worked fine
- When I tried to login to the admin i got Page not found message.
- When I removed the password protection htaccess from admin, then login to admin worked again.

What else I tried without success:
- I added various rewrite conditions to the opencart's htaccess but none of them seemed to work eg
after

Code: Select all

RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
i inserted

Code: Select all

RewriteCond %{REQUEST_URI} !^/admin/
but it didn't work
I also tried numerous RewriteCond and RewriteRule syntaxes but it either didn't work or it gave me server error.

Can someone help in this matter ?
Last edited by dither on Sat Feb 02, 2013 10:24 pm, edited 1 time in total.

New member

Posts

Joined
Sun Apr 29, 2012 12:40 pm

Post by bigal » Sat Feb 02, 2013 10:07 pm

Why don't you try using the protected directory tool provided by your webhosting control panel to password protect admin directory instead of creating .htacess yourself. Password protect directory involves creating password file using htpassword and in .htacesss points to that password file.
Using webhosting control panel tool is much easier.

Best Regards/Allen Chen


Active Member

Posts

Joined
Wed Sep 21, 2011 9:02 am

Post by dither » Sat Feb 02, 2013 10:19 pm

Why don't you try using the protected directory tool provided by your webhosting control panel to password protect admin directory instead of creating .htacess yourself. Password protect directory involves creating password file using htpassword and in .htacesss points to that password file.
Using webhosting control panel tool is much easier.
This is not the problem here, please read the post carefully, after all I know how to do it manually ...
Last edited by dither on Sat Feb 02, 2013 10:24 pm, edited 1 time in total.

New member

Posts

Joined
Sun Apr 29, 2012 12:40 pm

Post by dither » Sat Feb 02, 2013 10:22 pm

Ok, after spending my whole afternoon getting this to work, i figured out the solution and I'm posting it here if anyone's interested to do the same.

Solution for having both SEO enabled and password protect the admin directory.


1) Open .htaccess and at the rewrite rules change this:

Code: Select all

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
To this:

Code: Select all

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
If you have renamed your admin directory, replace "admin" with whatever you renamed it.

2) Create another .htaccess file inside the admin directory and place the password authentication text. (If you don't know how to do that manually, you can create that .htaccess file and the required authentication text automatically from your cPanel. Just go to "Security -> Password protect directories" in cPanel and do it).

3) After you create the .htaccess file (manually or automatically) go to the admin directory and open the .htaccess file with a text editor and insert this text above everything:

Code: Select all

# Workaround for SEO & Password protection to work
ErrorDocument 401 default
That should do the trick ! For the above solution, credit goes to this post

New member

Posts

Joined
Sun Apr 29, 2012 12:40 pm

Post by bastywebb » Thu Apr 04, 2013 10:37 pm

I followed your instructions and managed to get the server login box to display. But upon entering the correct login details I still see the page not found page, rather than the opencart admin area. Has anyone else had this problem and found a fix?

UPDATE (MY BAD):

I hadn't uploaded the .htpasswd file to the right location. I thought it was accepting my login credentials because the login box disappeared after entering them. But I think it just realised the file was missing. It works fine now.

Thanks a lot.

Newbie

Posts

Joined
Mon Nov 05, 2012 10:55 pm

Post by NMB123 » Wed Nov 11, 2015 10:33 pm

Thanks for your help with this. Works perfect ;) This is one of the first times that I've actually found something useful on this forum.

Regards John


Newbie

Posts

Joined
Sat May 19, 2012 11:35 pm
Location - UK
Who is online

Users browsing this forum: stefansmith129 and 211 guests