Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / Installing Zen Cart / Installing on a Linux/Unix Server / Need help for .htaccess redirect: change domain and subdirectory ONLY; leave ZC pages

Need help for .htaccess redirect: change domain and subdirectory ONLY; leave ZC pages

Locked

Started by donn on 8 Apr 2010, 10:49 PM · Views: 4,443

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
8 Apr 2010, 10:49 PM
#1
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Post #1 by donn

Hi....

I've been reading up about .htaccess redirect commands.

What I am trying to do is this:

Redirect ALL pages from:

oldsite.com/Cart/ZCFiles

and

www.oldsite.com/Cart/ZCfiles

to

newsite.com/ZCfiles

What I tried is this:

Options +FollowSymLinks 
RewriteEngine on
RewriteRule ^oldsite.com/Cart(/)?$ http://newsite.com(/)?$ [R=301, L]
RewriteRule ^oldsite.com/Cart(/)?$ http://newsite.com(/)?$ [R=301, L]

But...it didn't work. :(

I have read a bunch from Apache and other sites, but can't find the answer. Anyone with a link to info or a clue would be appreciated.

(Looking at another .htaccess set of commands that are listed on the Zen Cart Community forum elsewhere makes me wonder if I handled the subdirectory part correctly, or if I'm WAY off!!)

# redirects any URL that includes: /images/wp- with 'wp-' being anything that ends with '.php'
# this allows for images named such as 'wp-header.jpg' to work
RedirectMatch Permanent ^/(.*[images]+)/(wp-.*\.php)$ /page_not_found.php

I know the function of this is different, but I see the subdirectory part is handled way differently than what I attempted.

10 Apr 2010, 7:48 PM
#2
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Post #2 by g1smd

RewriteRule sees only URL paths, not domain names, nor query strings.

This should work:

ErrorDocument 404 /index.php?main_page=page_not_found

Options +FollowSymLinks 
RewriteEngine on

# Fixes for old site

# Index Redirect for oldsite /Cart/index.php request with no parameters 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /Cart/index\.php\ HTTP/
RewriteRule ^Cart/index\.php$ http://examplenewsite.com/? [R=301,L]

# Index Redirect for oldsite /Cart/(index.php)?main_page=index(&cPath=<blank>) request
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /Cart/(index\.php)?\?main_page=index(&cPath=)?\ HTTP/
RewriteRule ^Cart/(index\.php)?$ http://examplenewsite.com/? [R=301,L]

# Redirect old domain with or without port number etc to new domain
RewriteCond %{HTTP_HOST}   ^(www\.)?exampleoldsite\.com [NC]
RewriteRule ^Cart/(.*) http://examplenewsite.com/$1 [R=301,L]

# Fixes for new site

# Index Redirect for newsite /index.php request with no parameters
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://examplenewsite.com/? [R=301,L]

# Index Redirect for newsite /(index.php)?main_page=index(&cPath=<blank>) request
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index\.php)?$ http://examplenewsite.com/? [R=301,L]

# Redirect www and/or trailing port number etc, to non-www on new site
RewriteCond %{HTTP_HOST}  !^(examplenewsite\.com)?$
RewriteRule (.*) http://examplenewsite.com/$1 [R=301,L]

All rules are needed and all start and end anchoring is coded exactly as intended.

Online since 1995.

10 Apr 2010, 9:05 PM
#3
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Post #3 by g1smd

There's a slightly more efficient way to do this, with instead two .htaccess files affected instead of just the root file.

This code goes in the .htaccess file in the /Cart/ folder:```
Options +FollowSymLinks
RewriteEngine on

Fixes for old site

Index Redirect for oldsite /Cart/index.php request with no parameters

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /Cart/index.php\ HTTP/
RewriteRule ^index.php$ http://examplenewsite.com/? [R=301,L]

Index Redirect for oldsite /Cart/(index.php)?main_page=index(&cPath=<blank>) request

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /Cart/(index.php)??main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index.php)?$ http://examplenewsite.com/? [R=301,L]

Redirect old domain with or without port number etc to new domain

RewriteCond %{HTTP_HOST} ^(www.)?exampleoldsite.com [NC]
RewriteRule ^(.*) http://examplenewsite.com/$1 [R=301,L]




This code goes in the **.htaccess** file in the **root** folder:```
Options +FollowSymLinks 
RewriteEngine on

# Fixes for new site

# Index Redirect for newsite /index.php request with no parameters
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://examplenewsite.com/? [R=301,L]

# Index Redirect for newsite /(index.php)?main_page=index(&cPath=<blank>) request
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index\.php)?$ http://examplenewsite.com/? [R=301,L]

# Redirect www and/or trailing port number etc, to non-www on new site
RewriteCond %{HTTP_HOST}  !^(examplenewsite\.com)?$
RewriteRule (.*) http://examplenewsite.com/$1 [R=301,L]

Online since 1995.

11 Apr 2010, 6:57 AM
#4
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Post #4 by g1smd

Ooops. The final block of code in the very last example should have read...

# Redirect www and/or trailing port number etc, to non-www on new site
RewriteCond %{HTTP_HOST}  !^(examplenewsite\.com)?$
[b]RewriteCond %{REQUEST_URI} !^/(admin|Cart) [NC][/b]
RewriteRule (.*) http://examplenewsite.com/$1 [R=301,L]

Online since 1995.