Post by Mahakal » Sat Feb 04, 2017 10:57 pm

Dear Opencart Users,
I LOVE OPENCART
Please let me know how to use .htaccess for my opencart store version 2.0.3.1, my store is installed in public_html.The present .htaccess contains nothing.Please provide me the all the necessary codes that are required for friendly SEO url and some more codes that are vital in .htaccess file with steps.It will be a very great help.
Thanks in Advance.
Please find the present .htaccess file in attachment.

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Sat Feb 04, 2017 11:53 pm

Here is the default .htaccess that will enable SEO URLs, plus some added goodies for compression, caching, etc.

Code: Select all

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Order deny,allow
 Deny from all
</FilesMatch>

RewriteEngine On

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

ExpiresActive On
ExpiresDefault A0

<FilesMatch "\.(gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG)$">
  ExpiresDefault A2592000
  Header append Cache-Control "public"
</FilesMatch>

<FilesMatch "\.(less|js|css|gz)$">
  ExpiresDefault A2592000
  Header append Cache-Control "proxy-revalidate"
</FilesMatch>

<FilesMatch "\.(php)$">
  ExpiresActive Off
  Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
  Header set Pragma "no-cache"
</FilesMatch>

<IfModule mod_headers.c>
  <FilesMatch "\.(less|js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE font/woff .woff
AddOutputFilterByType DEFLATE application/x-font-woff
AddOutputFilterByType DEFLATE application/font-woff
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-otf

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Order allow,deny
Allow from all

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Sun Feb 05, 2017 5:26 pm

Thanks a ton,
Please tell where to place this .htaccess as I had two one outside the public_html and one inside the public_html I just edited the inside .htaccess file with 404 Error and deleted the outside .htaccess file (It had nothing) ,that worked and it showed the custom 404.html.But a major issue came up as I was changing over my admin/settings and clicked save button the following error occured.Please help SIR.

FORBIDDEN
You don't have permission to access /admin/index.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Sun Feb 05, 2017 7:43 pm

It goes in your public_html folder

You should not have one in your admin folder

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Sun Feb 05, 2017 10:20 pm

What about the below error ? Sir
FORBIDDEN
You don't have permission to access /admin/index.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Mon Feb 06, 2017 1:45 am

That is not caused by the above .htaccess

You mentioned you had an .htaccess above the poublic_html folder.

Maybe that is the cause

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Mon Feb 06, 2017 3:24 pm

I have deleted the .htaccess which was outside the public_html but the issue is still there.

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Mon Feb 06, 2017 4:06 pm

and if you replace the one I put with just the following:

Code: Select all

RewriteEngine On

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

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Thu Feb 09, 2017 2:33 am

Dear Sir,
Please find my present .htaccess file and the codes that you provided now I am getting error
Page cannot be found and it redirecting to my home page i.e to the index.php whenever I am trying to click USE SEO URL to yes and pressing save button in admin dashboard.Please help me get out of it.

PLEASE POINT OUT THE ERRORS IF ANY TELL ME WHAT IS THE REPLACEMENT.

Code: Select all

RewriteEngine on
RewriteCond ${LeechProtect:/home/mysitename/public_html:%{REMOTE_USER}:%{REMOTE_ADDR}:4:IrAxFfga0idn1Hw7nrfbdfddfCW527UEX4k} leech
RewriteRule .* /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{36}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
<Files 403.shtml>
order allow,deny
allow from all
</Files>

RewriteCond %{HTTP_REFERER} !^http://mysitename.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mysitename.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysitename.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysitename.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mysitename.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mysitename.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mysitename.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mysitename.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
ErrorDocument 404 /404.html


    <FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
     Order deny,allow
     Deny from all
    </FilesMatch>

    RewriteEngine On

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

    ExpiresActive On
    ExpiresDefault A0

    <FilesMatch "\.(gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG)$">
      ExpiresDefault A2592000
      Header append Cache-Control "public"
    </FilesMatch>

    <FilesMatch "\.(less|js|css|gz)$">
      ExpiresDefault A2592000
      Header append Cache-Control "proxy-revalidate"
    </FilesMatch>

    <FilesMatch "\.(php)$">
      ExpiresActive Off
      Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
      Header set Pragma "no-cache"
    </FilesMatch>

    <IfModule mod_headers.c>
      <FilesMatch "\.(less|js|css|xml|gz)$">
        Header append Vary Accept-Encoding
      </FilesMatch>
    </IfModule>

    # compress text, HTML, JavaScript, CSS, and XML
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE font/woff .woff
    AddOutputFilterByType DEFLATE application/x-font-woff
    AddOutputFilterByType DEFLATE application/font-woff
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-otf

    # remove browser bugs
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    Order allow,deny
    Allow from all

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Thu Feb 09, 2017 3:13 am

So you chose not to put the default .htaccess as I posted and added a load of other htaccess rules.

Unfortunately, I can only lead a horse to water, I cannot make him drink it.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Thu Feb 09, 2017 4:35 pm

I have added your codes with the codes that was previously present still the error is showing up.
Do I need to delete the previous codes or what I have to do?

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Thu Feb 09, 2017 9:19 pm

Yes, just use the code I posted.

Remove all other code

Make a backup of your old file just in case you need it. It is however, not default OpenCart code that you had previously, so I am not sure of it's purpose or why it is needed, and is most likely causing issues.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Fri Feb 10, 2017 1:13 am

Sir,
I did exactly as you said but the problem is again there when pressing the save button on admin panel to use SEO URL it is redirecting to my home page before showing the below error.

Server Connection Closed
Description: The server requested closed the connection before the transaction was completed.

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Fri Feb 10, 2017 1:29 am

Check with your server host that you have mod_rewrite enabled

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Fri Feb 10, 2017 11:00 pm

Yes they have enabled the mod_rewrite, still while saving it is redirecting to home page " PAGE NOT FOUND" message.
Is there any way to check or enable mod_rewrite from cpanel.

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Fri Feb 10, 2017 11:18 pm

Please also try a different web browser.

After checking your last error message, it seems it could be web browser related.

Also if you have a firewall on your computer, it could also be causing the issue.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Fri Feb 10, 2017 11:45 pm

Tried other browsers ,enabled and disabled firewall also still facing same issue , not getting saved the USE SEO URL's from dashboard.
THE PAGE YOU REQUESTED CANNOT BE FOUND!

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by Mahakal » Sat Feb 11, 2017 12:08 am

I have searched regarding this issue found the below information should I use these .

1.) # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
(All the files are inside public_html should I use the below code after RewriteBase /
RewriteBase / mysitename)


2.) Options +FollowSymlinks
# Prevent Directoy listing
Options -Indexes
(What are these codes for and how to use them and where in .htacces file?)

Like This #before +FollowSymlinks or any other syntax.

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am

Post by uksitebuilder » Sat Feb 11, 2017 12:20 am

If your store is in the root of your domain then it should be

Rewritebase /

You can try either commenting out the Symlinks line (put # at beginning of line), or adding it if you don’t already have it

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by Mahakal » Sat Feb 11, 2017 4:29 pm

No! It too didn't work :-(

New member

Posts

Joined
Sun Sep 04, 2016 2:42 am
Who is online

Users browsing this forum: No registered users and 6 guests