Zen Cart Logo
Forums / General Questions / redirects in htacess help

redirects in htacess help

Views: 1,572

Results 1 to 20 of 26
3 Mar 2016, 6:40 AM
#1
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

redirects in htacess help

###############################################################################

Add any custom 301 redirects

hey guys trying to redirect my http:// to www or something like that just dont want duplicate content
now i put the below code into my .htacess file and redirects work as they should but if i got to a product on my site and add to cart just brings up your shopping cart is empty and doesn't add item to cart. if i remove this redirect items will get added to cart fine anyone please help.

###############################################################################

Notes:

In general these should be few and far between. If you use a RewriteRule

be sure to add the L flag to let Apache mod_rewrite know to stop processing

and skip any RewriteRules defined later in the .htaccess file.

###############################################################################
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.anarchyangels.net
RewriteRule (.*) http://www.anarchyangels.net/$1 [R=301,L]
</IfModule>

3 Mar 2016, 2:46 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: redirects in htacess help

Try the following

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.anarchyangels.net$
RewriteRule ^(.*)$ http://www.anarchyangels.net/$1 [R=301]

3 Mar 2016, 6:54 PM
#3
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

thanks for the reply mate but this just returns a blank page lol you would think a 301 redirect would be easy lol frustrating

3 Mar 2016, 10:53 PM
#4
terragirl avatar

terragirl

Zen Follower

Join Date:
Jun 2010
Location:
Austria
Posts:
123
Plugin Contributions:
0

Re: redirects in htacess help

The code given above should work, same one I use on sites.

Have you made sure that in your site's /include/configure.php (frontend & admin), you are using "www.anarchyangels.net" as domain name?

3 Mar 2016, 11:21 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: redirects in htacess help

terraGirl:

The code given above should work, same one I use on sites.

Have you made sure that in your site's /include/configure.php (frontend & admin), you are using "www.anarchyangels.net" as domain name?

Having followed the link, the answer is no, the server information for the store side of the ZC store is set to exclude the www. Not exactly sure why the old school www. Is trying to be forced, but first ZC needs to have the uri that is expected to be had before pushing visitors to one direction or the other.

4 Mar 2016, 1:35 AM
#6
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

Ok I didn't realise I had to check config.php just was putting it into the .htacess file my origianl code I got worked I got that from ZenCart instructions sure it said to put it into the htacess file is is there a guid for ZenCart to show all steps required so I don't make a mess lol thanks in advance:)

4 Mar 2016, 1:37 AM
#7
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

Also I was trying to force the www as this is what has been set in Google tools and read that you should use 301 redirects to stop getting bad rankings

4 Mar 2016, 6:43 AM
#8
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

includes/config.php

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

admin/includes/config.php

define('HTTP_SERVER', 'http://anarchyangels.net');
define('HTTPS_SERVER', 'https://anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://anarchyangels.net');

lol shouldn't these match
can i just edit these without breaking my site

4 Mar 2016, 6:58 AM
#9
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: redirects in htacess help

Yes, they should match. If the site is setup properly, you can change one file to match the other, without breaking the site.> mydakota:

includes/config.php

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

admin/includes/config.php

define('HTTP_SERVER', 'http://anarchyangels.net');
define('HTTPS_SERVER', 'https://anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://anarchyangels.net');

lol shouldn't these match
can i just edit these without breaking my site

4 Mar 2016, 7:12 AM
#10
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

ok i changed them both to

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

then added

###############################################################################
# Add custom headers and options
###############################################################################
# Notes:
#
# Examples: Adding IE compatibility / edge flags, language and encoding flags,
# php or suphp directives, configure other Apache modules such as page_speed,
# and enable or disable Apache httpd options.
#
# Do NOT configure anything directly relating to physical or virtual resources
# in this section. These should be addressed later on in this file.
###############################################################################
#Options -Indexes

###############################################################################
# Enable mod_rewrite processing using the rules in this .htaccess file
###############################################################################
# Notes:
#
# <IfModule> should be avoided at all costs. If mod_rewrite is not available
# it is almost always better to return HTTP 500 status. This way we see there
# is an issue as soon as the .htaccess file is uploaded.
#
# For mod_rewrite to work, the Apache server option to allow symbolic links to
# be followed must be enabled. Most providers supporting mod_rewrite will
# already have it enabled for you, but if your rewrite rules are not working
# you can un-comment the first directive below to manually enable the option.
#
# Don't forget, mod_rewrite directives are processed in order until a matching
# RewriteRule with the [L] flag is encountered. So the more specific a rule is
# the closer it should appear to the top of this file.
###############################################################################
#Options +FollowSymLinks
RewriteEngine on

###############################################################################
# Tell mod_rewrite where this file is relative to the server document_root
###############################################################################
# Notes:
#
# This directive should only be enabled if this .htaccess file is not placed
# in the document_root (usually public_html, www, or web) of the (sub)domain.
#
# An easy way to determine the location relative to the server document_root is
# to look at the URL used to access a file in this folder. For example if you
# access a "page" in the same folder as this file by typing in the URL
# "www.mydomain.com/myfolder/index.html" then "myfolder" will be the location
# of this file relative to the server document_root.
#
# Another quick and easy way to determine the correct setting for this is to
# look at the defined value for DIR_WS_CATALOG and DIR_WS_HTTPS_CATALOG in
# Zen Cart's configure.php files. All three values should match.
#
# Don't forget the leading and trailing /. This directive requires both!
###############################################################################
#RewriteBase /shop/


###############################################################################
# Redirect if request was for index.php (no query)
###############################################################################
# Notes:
#
# This is only required if the site generates references to index.php with no
# parameters. This rule will force a 301 redirect to the site root when a
# request is made for "/index.php" with no query terms (?key=value).
###############################################################################
#RewriteCond %{QUERY_STRING} ^$
#RewriteRule ^index\.php$ / [R=301,L]


###############################################################################
# Add any custom 301 redirects
###############################################################################
# Notes:
#
# In general these should be few and far between. If you use a RewriteRule
# be sure to add the L flag to let Apache mod_rewrite know to stop processing
# and skip any RewriteRules defined later in the .htaccess file.
###############################################################################
define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

###############################################################################
# Redirect if request was for index.php (with or without query)
###############################################################################
# Notes:
#
# This is a performance optimization. If the request is for index.php simply
# pass the request on and do not process any other mod_rewrite directives in
# this file.
#
# Basically this avoids the overhead of checking if index.php is a real file
# or directory (used in subsequent mod_rewrite rules) before sending the
# request to index.php.
###############################################################################
RewriteRule ^index\.php$ - [L]


###############################################################################
# Start Ultimate (SEO) URLs
###############################################################################
# Notes:
#
# You should not make any changes in this section unless you really understand
# how it will impact your web site. Mistakes can break things.
###############################################################################

# Handles the new URL formats
RewriteRule ^(.*)-c-([0-9_]+)/(.*)-p-([0-9]+)(.*)$ index\.php?main_page=product_info&products_id=$4&cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9_]+)/(.*)-pi-([0-9]+)(.*)$ index\.php?main_page=popup_image&pID=$4&cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9_]+)/(.*)-pr-([0-9]+)(.*)$ index\.php?main_page=product_reviews&products_id=$4&cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9_]+)/(.*)-pri-([0-9]+)(.*)$ index\.php?main_page=product_reviews_info&products_id=$4&cPath=$2&%{QUERY_STRING} [L]

# Original (unchanged) URL formats
RewriteRule ^(.*)-p-([0-9]+)(.*)$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-m-([0-9]+)(.*)$ index\.php?main_page=index&manufacturers_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pi-([0-9]+)(.*)$ index\.php?main_page=popup_image&pID=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pr-([0-9]+)(.*)$ index\.php?main_page=product_reviews&products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pri-([0-9]+)(.*)$ index\.php?main_page=product_reviews_info&products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-ezp-([0-9]+)(.*)$ index\.php?main_page=page&id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9_]+)(.*)$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]

# Rewrite all other requests (if the file / directory does not exist)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php?main_page=$1&%{QUERY_STRING} [L]

###############################################################################
# Add any other directives relating to the handling of physical files
###############################################################################
# Notes:
#
# If processing makes it this far, the request was for a real file or folder.
# Example: Adding further processing related to browser caching or security.
###############################################################################

this returns a blank page with http://anarchyangels.net but ok with www.

but if i use this code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.anarchyangels\.net
RewriteRule (.*) http://www.anarchyangels.net/$1 [R=301,L]
</IfModule> 

everything redirects and seems to work ok except when adding product to cart just returns to page your shopping cart is empty
hope that makes sense

4 Mar 2016, 7:45 AM
#11
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: redirects in htacess help

mydakota:

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

This should be in your configure.php files not in the .htaccess
4 Mar 2016, 7:56 AM
#12
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

it is the .htacess fill in root i am meant to edit or is it some other one sorry i am a bit new to this sorry for being dumb

4 Mar 2016, 7:57 AM
#13
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

yes that is in my config file not my .htaccess file lol

4 Mar 2016, 8:01 AM
#14
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

config file admin

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

includes/

// Define the webserver and path parameters
  // HTTP_SERVER is your Main webserver: eg-http://www.your_domain.com
  // HTTPS_SERVER is your Secure webserver: eg-https://www.your_domain.com
  define('HTTP_SERVER', 'http://www.anarchyangels.net');
  define('HTTPS_SERVER', 'https://www.anarchyangels.net');

root dir .htacess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.anarchyangels.net$
RewriteRule ^(.*)$ http://www.anarchyangels.net/$1 [R=301] 
4 Mar 2016, 8:03 AM
#15
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: redirects in htacess help

Probably need to change the red highlighted line

define('HTTP_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_SERVER', 'https://www.anarchyangels.net');
define('HTTP_CATALOG_SERVER', 'http://www.anarchyangels.net');
define('HTTPS_CATALOG_SERVER', 'https://www.anarchyangels.net');

to

define('HTTP_CATALOG_SERVER', 'http[B]s[/B]://www.anarchyangels.net');

Looks like we cross posted

What you posted last is fine

4 Mar 2016, 8:24 AM
#16
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

So even though it says define http I put

define('HTTP_CATALOG_SERVER', 'https://www.anarchyangels.net');
In its place also I'm not currently using https if that makes any difference

4 Mar 2016, 8:58 AM
#17
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

ok so i changed that to https and now this one works

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.anarchyangels\.net
RewriteRule (.*) http://www.anarchyangels.net/$1 [R=301,L]
</IfModule> 

but this one below still doesn't work lol I'm sure it shouldn't be this hard lol is there anything wrong with the code that seems to be working vs
this one

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.anarchyangels.net$
RewriteRule ^(.*)$ http://www.anarchyangels.net/$1 [R=301]
4 Mar 2016, 9:09 AM
#18
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

omg now its not working either same shopping cart issue
think ill just have to give up starting to make me mad lol :(

4 Mar 2016, 9:29 AM
#19
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: redirects in htacess help

from what i read and have found some plugin called Ultimate URLs i have no idea what this is but sound like this could be causing my problems
do i need this plugin and can i remove it :)

4 Mar 2016, 11:13 AM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: redirects in htacess help

So this is the first time that it has been brought up that a uri rewriter is also trying to be installed. If that is the desire the question should be raised in the applicable uri rewriter thread, though can say there is an obvious error in the first .htaccess. There is php code (define('HTTP_SERVER' etc)) that should not be there. Further the first htaccess doesn't include anything to force www. To be prepended... Further, when stated that everything works does that mean that the add-to-cart was verified functional?

The second .htaccess was previously identified as incorrect with a third option provided, what about when that third option is applied?