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?
Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.
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]
Thanks for this, I copied it and replaced your version with my version with the following issues: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:
edited to add your 'store' subdirectory to the base otherwise your SEO URLs would failCode: Select all
RewriteEngine on RewriteBase /store/ RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
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.
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: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)
.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.
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
Thank you so much for this, it seems to be PARTLY working:-uksitebuilder wrote:Ah Ok it was just your .htaccess was a little messed up
Replace it's contents with the following
I removed your configs as they were fineCode: 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



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.
uncommented - still the sameuksitebuilder wrote:This is really strange
Try uncommenting this line
Options +FollowSymlinks

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.
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.
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 fileuksitebuilder 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) ?
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.
re-uploading admin files made no differenceuser wrote:The root of my domain has no htaccess fileuksitebuilder 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) ?
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.
Spoke to the host and they said everything fine from their end and it is a problem with my code in htaccess fileuser wrote:re-uploading admin files made no differenceuser wrote:The root of my domain has no htaccess fileuksitebuilder 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) ?
Im just reuploading the default admin files except config.php and will get back to you
Do you think it is a host problem?![]()
![]()
![]()
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?
Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.
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.
By removing the RewriteBase line as per my file below everything except redirect is working fineuksitebuilder wrote:If you remove the RewriteBase line completely, do your SEO URLs still work and everything else (apart from www redirect)?
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.
I know, I thought it would be easy too.... technology hehyamaha600 wrote:surely you just want to do a 301 redirect on your server

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.
Users browsing this forum: No registered users and 3 guests