0

I am new here, I really need help I am creating a new site with opencart version 1.5.5.1 & I have tried creating my own htaccess file but it is not doing what I want it to do. I have tried a lot of the code from this site and my host sd, opencart is not built for doing this, which I don't believe. But they could be right cause its not working for me. I have a good seo module SEO Pack Pro which is installed but I don't think it is preventing the changes in the htaccess file.

Main problem is to eliminate duplication of the urls with 301 redirects and get a header code of 200 for the www & 301 for the non www . I am pretty sure that's how it is suppose to be

So what I need is to start from scratch to make a new htaccess file:

So again, redirect all non www urls to www urls not just the home page with 301 redirects & I want to make sure there is a trailing slash after all the www urls. I don't need a slash after non www urls cause being redirected ? Also need home page redirected from index.php & index.htm, index.html to http://www.example.com/

Also a trailing slash after each directory & sub directories, I think my site goes down 3 levels of sub directories and right now I don't care if there is a trailing slash after the file name and removing the file extension or no slash after the file name - I have read the arguments on both sides of that and I think it doesn't matter for the file name to have a trailing slash. So sorry for the book here, if anyone can help me out with this ? Thanks, Nicole

Nicole
  • 1
  • 1

2 Answers2

0

This .htaccess should help.

RewriteEngine on
RewriteBase /

# redirect non-www urls
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

# redirect all home pages to / (root)
RewriteCond %{REQUEST_URI} ^/index\.(php|html?)
RewriteRule ^.*$ / [R=301,L]

# add trailing slash to dirs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ $1/ [R=301,L]
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
0

Don't forget to add request method for the trailing slash. This is needed for login/lostpass/registration.. etc My .htaccess contains

# Add trailing slash to URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
5ulo
  • 749
  • 1
  • 8
  • 21