Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Redirect index.php and / and non / to .html version of urls Rate Topic   * * * * * 1 votes

 
  • pjlee
  • Newbie
  • Members
  • Join Date: 20-Jan 12
  • 11 posts

Posted 22 May 2013 - 09:26 AM #1

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:

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

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

Removing the suggested code has fixed the tracking issue but has created another problem.

This part of the code did 2 things:

1. Redirected urls with a /( forward slash) and non / (forward slash) to the .html version for the url , for example:

http://www.mysite.co.uk/cat1
and
http://www.mysite.co.uk/cat1/
redirected to
http://www.mysite.co.uk/cat1.html


2. Redirected http://www.mysite.co.uk/index.php to http://www.mysite.co.uk/ (same page with different urls)
Both of these things have stopped working since removing the suggested code. My htaccess now looks like this:

Options +FollowSymlinks
RewriteEngine on
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]

DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
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]
</IfModule>

Please can someone recommend what to add to my htaccess to achieve the redirects and keep visitor tracking?

 
  • pjlee
  • Newbie
  • Members
  • Join Date: 20-Jan 12
  • 11 posts

Posted 22 May 2013 - 11:40 AM #2

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 http://forum.cs-cart...website-step-1/


Options +FollowSymlinks
RewriteEngine on
<IfModule mod_expires.c>
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
  ExpiresActive On
  ExpiresDefault "access plus 10 years"
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\.(js|css))$ smartoptimizer/?$1

<IfModule mod_expires.c>
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^(.*\.(js|css|html?|xml|txt))$ smartoptimizer/?$1
</IfModule>
<IfModule !mod_expires.c>
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^(.*\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico))$ smartoptimizer/?$1
</IfModule>
</IfModule>
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
FileETag none
</FilesMatch>

<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|php|html)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
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
<IfModule mod_rewrite.c>
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]
</IfModule>