Post by aljawaid » Fri Nov 07, 2014 11:55 pm

Hello, totally confused here hoping for some help:

I am trying to force users who don't enter 'www' to be redirected to the 'www' version of my site.

Based on advice from: http://www.htaccessbasics.com/force-www-nonwww-domain/

Below is my HTACCESS file:
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.co\.uk [NC]
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]

The problem is, when I test with NON 'www' it goes to: http://www.pennyprofits.co.uk.co.uk/ which generates a 'Server Not Found' and is also incorrect.

My actual store will be: www.domain.co.uk/store

Basically, if a user goes to http://domain.co.uk/store he should be forced to http://www.domain.co.uk/store whether it is SSL or not

Any idea what I have done wrong?
Last edited by aljawaid on Wed Feb 27, 2019 6:35 am, edited 1 time in total.

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Fri Nov 07, 2014 11:59 pm

There should be no entry point to your store via SSL, so you need not worry about that.

Here is what I use:

Code: Select all

RewriteEngine on
RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
edited to add your 'store' subdirectory to the base otherwise your SEO URLs would fail

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 12:23 am

uksitebuilder wrote:There should be no entry point to your store via SSL, so you need not worry about that.

Here is what I use:

Code: Select all

RewriteEngine on
RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
edited to add your 'store' subdirectory to the base otherwise your SEO URLs would fail
Thanks for this, I copied it and replaced your version with my version with the following issues:

The store front still shows 404 error as it adds an extra '.co.uk' on it
The admin page is now 404 to login or logout

???

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sat Nov 08, 2014 12:33 am

I'm assuming your store is in yourdomain.com/store/

Please paste the contents of your .htaccess here

Please paste the contents of your config.php and admin/config.php removing any sensitive data)

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 12:51 am

uksitebuilder wrote:I'm assuming your store is in yourdomain.com/store/

Please paste the contents of your .htaccess here

Please paste the contents of your config.php and admin/config.php removing any sensitive data)
Appreciate all your help, as requested:

.htaccess file:

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

#Options +FollowSymlinks

# Prevent Directoy listing 
#Options -Indexes

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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

RewriteBase /store/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^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)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

# Redirect non-www urls to www
RewriteEngine on
RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sat Nov 08, 2014 12:56 am

Ah Ok it was just your .htaccess was a little messed up

Replace it's contents with the following

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

#Options +FollowSymlinks

# Prevent Directoy listing
#Options -Indexes

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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^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)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none
I removed your configs as they were fine

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 3:24 am

uksitebuilder wrote:Ah Ok it was just your .htaccess was a little messed up

Replace it's contents with the following

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

#Options +FollowSymlinks

# Prevent Directoy listing
#Options -Indexes

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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^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)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none
I removed your configs as they were fine
Thank you so much for this, it seems to be PARTLY working:-

:( It now redirects to my domain instead of pennyprofits.co.uk/store
:( Admin login gives me 404 error preventing me from loggin in - whether I use WWW or not
:( The SEO doesnt work either www.pennyprofits.co.uk/store/atta

Any ideas?

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sat Nov 08, 2014 4:21 am

This is really strange

Try uncommenting this line

Options +FollowSymlinks

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 4:26 am

uksitebuilder wrote:This is really strange

Try uncommenting this line

Options +FollowSymlinks
uncommented - still the same :(

SEO works though

But cant sign into admin with or without www
without www takes me to domain and not store

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sat Nov 08, 2014 8:33 am

Have you got a htaccess in your admin flder by any chance ?

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 9:38 am

uksitebuilder wrote:Have you got a htaccess in your admin flder by any chance ?

No sorry

Below is the directory of my admin folder
/store/admin/config.php
/store/admin/favicon.ico
/store/admin/index.php
/store/admin/php.ini

Below is directory of my store folder
/store/.htaccess
/store/config.php
/store/crossdomain.xml
/store/favicon.ico
/store/index.php
/store/php.ini

Does that help? ???

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sat Nov 08, 2014 7:45 pm

hmmm, I am getting a little stumped on why this is happening myself now.

Have you tried reuploading the default opencart admn files (except for admin/config.php)

The only other thing I can think of is that in the root of your domain, do you have a .htaccess file in there (i.e. the directory above the subfolder) ?

User avatar
Guru Member

Posts

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

Post by aljawaid » Sat Nov 08, 2014 8:57 pm

uksitebuilder wrote:hmmm, I am getting a little stumped on why this is happening myself now.

Have you tried reuploading the default opencart admn files (except for admin/config.php)

The only other thing I can think of is that in the root of your domain, do you have a .htaccess file in there (i.e. the directory above the subfolder) ?
The root of my domain has no htaccess file

Im just reuploading the default admin files except config.php and will get back to you

Do you think it is a host problem?

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by aljawaid » Sat Nov 08, 2014 9:08 pm

user wrote:
uksitebuilder wrote:hmmm, I am getting a little stumped on why this is happening myself now.

Have you tried reuploading the default opencart admn files (except for admin/config.php)

The only other thing I can think of is that in the root of your domain, do you have a .htaccess file in there (i.e. the directory above the subfolder) ?
The root of my domain has no htaccess file

Im just reuploading the default admin files except config.php and will get back to you

Do you think it is a host problem?
re-uploading admin files made no difference ??? :( ??? :(
Last edited by aljawaid on Wed Feb 27, 2019 6:36 am, edited 1 time in total.

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by aljawaid » Sat Nov 08, 2014 9:54 pm

user wrote:
user wrote:
uksitebuilder wrote:hmmm, I am getting a little stumped on why this is happening myself now.

Have you tried reuploading the default opencart admn files (except for admin/config.php)

The only other thing I can think of is that in the root of your domain, do you have a .htaccess file in there (i.e. the directory above the subfolder) ?
The root of my domain has no htaccess file

Im just reuploading the default admin files except config.php and will get back to you

Do you think it is a host problem?
re-uploading admin files made no difference ??? :( ??? :(
Spoke to the host and they said everything fine from their end and it is a problem with my code in htaccess file

I started form scratch and put in just the below ONLY in the file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.+\.)([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$
RewriteRule ^(.*)$ http://www.%1/ [L,QSA,R=301]
Options +FollowSymlinks

# Prevent Directoy listing
#Options -Indexes

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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /store/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^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)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Now both www and non-www work but they dont link up to always be www (so im back to square one I guess)

At least I can get into the admin for the time being

Just wondering, does the order of these lines matter?
Last edited by aljawaid on Wed Feb 27, 2019 6:36 am, edited 2 times in total.

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by aljawaid » Sat Nov 08, 2014 10:08 pm

I think I might have sussed it out

This line makes the /store go back to root (.co.uk) folder and admin folder as 404 without www and ok with www but no redirect
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

the above line and below line gives me no access to admin at all
RewriteRule ^(.*)$ http://www.%1/ [L,QSA,R=301]

The only problem is, I don't have a clue what these lines mean in terms of characters lol

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by uksitebuilder » Sun Nov 09, 2014 5:17 pm

If you remove the RewriteBase line completely, do your SEO URLs still work and everything else (apart from www redirect)?

User avatar
Guru Member

Posts

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

Post by yamaha600 » Sun Nov 09, 2014 8:03 pm

surely you just want to do a 301 redirect on your server

New member

Posts

Joined
Sun Feb 05, 2012 9:55 pm

Post by aljawaid » Sun Nov 09, 2014 11:31 pm

uksitebuilder wrote:If you remove the RewriteBase line completely, do your SEO URLs still work and everything else (apart from www redirect)?
By removing the RewriteBase line as per my file below everything except redirect is working fine

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.+\.)([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Options +FollowSymlinks

# Prevent Directoy listing
#Options -Indexes

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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^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)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

but if i also include RewriteRule ^(.*)$ http://www .%1/ [L,QSA,R=301] into the above I get 500 server error

so the only thing that doesnt work is redirect to www and https

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by aljawaid » Sun Nov 09, 2014 11:32 pm

yamaha600 wrote:surely you just want to do a 301 redirect on your server
I know, I thought it would be easy too.... technology heh ???

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 3 guests