Redirect index.php and / and non / to .html version of urls

Hi,



I was encountering problems with my visitor tracking, it had stopped logging visitors. I emailed CS cart and they recommended I removed the following code from my htaccess:


<br />
RewriteCond %{THE_REQUEST} ^.*/index.php<br />
RewriteRule ^(.*)index.php$ /$1 [R=301,L]<br />
<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_URI} ^(.+)/$<br />
RewriteRule ^(.+)/$  /$1 [R=301,L]<br />
<br />
RewriteCond %{REQUEST_URI} !\.[^./]+$<br />
RewriteCond %{REQUEST_URI} !(.*)/$<br />
RewriteRule ^(.*)$ http://mysite.co.uk/$1.html<br />

```<br />
<br />
Removing the suggested code has fixed the tracking issue but has created another problem.<br />
<br />
This part of the code did 2 things:<br />
<br />
1. Redirected urls with a /( forward slash) and non / (forward slash) to the .html version for the url , for example:<br />
<br />
[url="http://www.mysite.co.uk/cat1"]http://www.mysite.co.uk/cat1[/url]<br />
and<br />
[url="http://www.mysite.co.uk/cat1/"]http://www.mysite.co.uk/cat1/[/url]<br />
redirected to<br />
[url="http://www.mysite.co.uk/cat1.html"]http://www.mysite.co.uk/cat1.html[/url]<br />
<br />
<br />
2. Redirected [url="http://www.mysite.co.uk/index.php"]http://www.mysite.co.uk/index.php[/url] to [url="http://www.mysite.co.uk/"]http://www.mysite.co.uk/[/url] (same page with different urls)<br />
Both of these things have stopped working since removing the suggested code. My htaccess now looks like this:<br />
<br />
```php
<br />
Options +FollowSymlinks<br />
RewriteEngine on<br />
RewriteCond %{HTTP_HOST} ^XXX.XXX.XXX.XX [nc,or]<br />
RewriteCond %{HTTP_HOST} ^mysite.co.uk [NC]<br />
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [L,R=301]<br />
<br />
DirectoryIndex index.html index.php<br />
<IfModule mod_rewrite.c><br />
RewriteEngine on<br />
# Pleas note that RewriteBase setting is obsolete use it only in case you experience  some problems with SEO addon.<br />
# Some hostings require RewriteBase to be uncommented<br />
# Example:<br />
# Your store url is http://www.yourcompany.com/store/cart<br />
# So "RewriteBase" should be:<br />
# RewriteBase /store/cart<br />
# RewriteBase /<br />
RewriteCond %{REQUEST_FILENAME} !\.(png|gif|ico|swf|jpe?g|js|css)$<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . index.php?sef_rewrite=1 [L,QSA]<br />
</IfModule><br />

```<br />
<br />
Please can someone recommend what to add to my htaccess to achieve the redirects and keep visitor tracking?

I solved the problems by making some changes to my htaccess. I have also added Smartoptimizer and Gzip-compression to try and speed things up a little. My htaccess now looks like this. It appears to be a little messy but is doing the job. If anyone would like to share any suggestions as to how I can improve it further I would be hugely appreciative.



Check out the Speed up your CS cart post to read more on Smartoptimizer and Gzip-compression [url=“Speed Up Your CS-Cart eCommerce Website - Step 1 - Hints & Modifications - CS-Cart Community Forums”]Speed Up Your CS-Cart eCommerce Website - Step 1 - Hints & Modifications - CS-Cart Community Forums




```php

Options +FollowSymlinks

RewriteEngine on





ExpiresActive On

ExpiresDefault “access plus 10 years”







RewriteEngine On



RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(..(js|css))$ smartoptimizer/?$1





RewriteCond %{REQUEST_FILENAME} -f

RewriteRule ^(.
.(js|css|html?|xml|txt))$ smartoptimizer/?$1





RewriteCond %{REQUEST_FILENAME} -f

RewriteRule ^(..(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico))$ smartoptimizer/?$1







FileETag none









SetOutputFilter DEFLATE





RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xx [nc,or]

RewriteCond %{HTTP_HOST} ^mysite.co.uk [NC]

RewriteRule ^(.
)$ http://www.mysite.co.uk/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^(.+)/$

RewriteRule ^(.+)/$ /$1 [R=301,L]



RewriteCond %{REQUEST_URI} !.[^./]+$

RewriteCond %{REQUEST_URI} !(.)/$

RewriteRule ^(.
)$ http://mysite.co.uk/$1.html [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index.(html?|php[45]?|[aj]spx?)\ HTTP/

RewriteRule index.(html?|php[45]?|[aj]spx?)$ http://www.mysite.co.uk/%1 [R=301,L]

DirectoryIndex index.html index.php



RewriteEngine on

Pleas note that RewriteBase setting is obsolete use it only in case you experience some problems with SEO addon.

Some hostings require RewriteBase to be uncommented

Example:

Your store url is http://www.yourcompany.com/store/cart

So “RewriteBase” should be:

RewriteBase /store/cart

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !.(png|gif|ico|swf|jpe?g|js|css)$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php?sef_rewrite=1 [L,QSA]



```