Post by jackfitz » Wed May 19, 2010 7:18 pm

With the latest open cart the .htaccess has the following code

Options +FollowSymlinks

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

I am trying to work out how to use the Rewrite function to direct www to non www version of the URL.
I have searched the forum and realised people have already brought this up, but I am not to sure how to add it in while leaving the code currently in the .htaccess file.

Any help would be great.

Outdoor Hammock


New member

Posts

Joined
Thu Mar 18, 2010 1:14 pm

Post by SteveSherry » Wed May 19, 2010 7:39 pm

Could you not change your config files to include the "www"?

My Website ¦ Summer Madness Special Offer ¦


Active Member

Posts

Joined
Thu Apr 08, 2010 7:47 am
Location - Wirral, UK

Post by jackfitz » Wed May 19, 2010 8:15 pm

Hum maybem but I know rewritig non www to www should do the job ok.

Outdoor Hammock


New member

Posts

Joined
Thu Mar 18, 2010 1:14 pm

Post by Xsecrets » Wed May 19, 2010 8:44 pm

mine looks like this. redirects all traffic to domain.com just incase someone puts in http://www.domain.com" onclick="window.open(this.href);return false;

Code: Select all

Options +FollowSymlinks

RewriteEngine On
RewriteBase / 
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC]
RewriteRule ^robots.txt$ $0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
oh yeah and I just noticed I also have a rule in there to exclude the robots.txt from rewriting.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Qphoria » Wed May 19, 2010 10:40 pm

Xsecrets, does your redirect work with paypal ipn? I've had a few people using redirects for www to non-www or vice versa but it breaks the IPN callback. It looks like you are using a correct 301 (which does support POST var redirection) so I think it should be ok. But I was curious if you know for sure.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Xsecrets » Wed May 19, 2010 11:54 pm

Qphoria wrote:Xsecrets, does your redirect work with paypal ipn? I've had a few people using redirects for www to non-www or vice versa but it breaks the IPN callback. It looks like you are using a correct 301 (which does support POST var redirection) so I think it should be ok. But I was curious if you know for sure.
didn't even think about it, but I've been using the redirect since I put up my store, and I haven't had any problems with paypal payments. they go through and get set as complete, so I'm guessing the callback is working fine.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Qphoria » Wed May 19, 2010 11:59 pm

excellent. Thanks!

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by thaiga » Thu May 20, 2010 4:16 pm

Inverse

i want http://www.domain.com
not want http://domain.com

how Write .htaccess

Newbie

Posts

Joined
Thu May 20, 2010 2:48 am

Post by jackfitz » Sat May 22, 2010 12:08 pm

Xsecrets thanks for posting the code.

I am looking to rewrite non www to www.
how exactly would I edit the code you posted?

Options +FollowSymlinks

Code: Select all

RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC]
    RewriteRule ^robots.txt$ $0 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

Outdoor Hammock


New member

Posts

Joined
Thu Mar 18, 2010 1:14 pm

Post by ifyouseek » Thu Jun 17, 2010 10:30 am

Thanks i have been looking for this.

I had a few problems with it at the begining, when i went to www.domain.com through firefox it didnt redirect but did show the site but using IE it just gave an error page. It didnt work until i moved the added code to the bottom of the .htaccess file, i don't know if that made the difference but this is the way mine is now

Code: Select all

Options +FollowSymlinks

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC]
RewriteRule ^robots.txt$ $0 [L]
Cheers again!!!

Active Member

Posts

Joined
Thu May 06, 2010 4:40 pm

Post by IsoNick » Wed Sep 28, 2011 12:53 am

This don't seem to work with the .htaccess file in OpenCart 1.5.1. I can't get it to work.

I want to go from non www, to always have www in front of my domain name. Can't anybody help with an updated code?

Also, at my domain, I can write anything instead of www, and my site will stille be shown. Let's say 'blahblah.domain.dk' or '12341243.domain.dk' - they will both show the content of www.domain.dk. How can I via .htaccess re-direct to www.domain.dk?

Thanks.

Newbie

Posts

Joined
Wed Jul 20, 2011 6:06 am
Location - Denmark

Post by jvizzini » Wed Sep 28, 2011 11:34 am

I too am experiencing this problem in 1.5.1. and this solution doesn't work.

If anyone could help that would be great.

New member

Posts

Joined
Wed Aug 17, 2011 5:44 am

Post by jvizzini » Wed Sep 28, 2011 11:35 am

i want no www.

the problem is if someone types in www.heartcaptions.com/ocstore the add to cart buttons dont work on the featured area

New member

Posts

Joined
Wed Aug 17, 2011 5:44 am

Post by ifyouseek » Sun Oct 09, 2011 3:31 am

hi, i have used this www to non www redirect provided by xsecrets for ages now...but it seems there is a problem with it.

When i visit http://www.example.com
it redirects to http://example.com successfully

but when i visit http://www.example.com/examplecatergory
it redirects to http://example.com/index.php?_route_=examplecatergory

I have tried placing the 3 lines of code bofore and after the orignal code but this index.php?_route_= keeps appearing, it seems since people ave linked in to our website using www. links google has started to index some of our pages with the index.php?_route_= inlclued in url

please advise on how to use this code correctly. i am running on 1.5.1 and will paste my htaccess below -

Code: Select all

SetEnv PHPRC "/home/folder/public_html"
DirectoryIndex index.php
Options +FollowSymlinks
#-Indexes

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC]
RewriteRule ^robots.txt$ $0 [L]

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L,QSA]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>



# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png)$">
  ExpiresDefault A604800
  Header append Cache-Control "public"
</FilesMatch>

# Set up 1 week caching on javascript and CSS
<FilesMatch "\.(js|css)$">
  ExpiresDefault A604800
  Header append Cache-Control "proxy-revalidate"
  SetOutputFilter DEFLATE
</FilesMatch>

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

Active Member

Posts

Joined
Thu May 06, 2010 4:40 pm
Who is online

Users browsing this forum: No registered users and 92 guests