Forums / General Questions / .htacess rewrite not working

.htacess rewrite not working

Locked

Views: 1,197

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
19 Apr 2010, 4:28 PM
#1
stuff4toys avatar

stuff4toys

Totally Zenned

Join Date:
May 2007
Location:
SW Florida
Posts:
1,062
Plugin Contributions:
1

.htacess rewrite not working

We just combines several domains to one primary domain. Unfortunately we moved the domain with Zen-Cart domain to a new name.

I created a domain forward with .htacess and am trying to re-direct the domain index.php requests to the new domain.

The domain redirect works, but the index.php re-directs are not working.

I have:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^ecabinetpro.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.ecabinetpro.com$
RewriteRule ^/?$ "http://www.capecabinetdepot.com/" [R=301,L]

Index Redirect for /index.php with no parameters

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

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index.php)??main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index.php)?$ http://www.capecabinetdepot.com/? [R=301,L]What do I need to change to make this seamless?
JOhn ><>

Newest Site: ChargerPros - Stuff4Toys

19 Apr 2010, 8:01 PM
#2
g1smd avatar

g1smd

Zen Follower

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

Re: .htacess rewrite not working

The last two rules should work OK as coded.

The first rule should be moved to be last. That rule could also be optimised by changing to:```

Canonical Redirect non-blank, non-www and/or appended port number to www [EXCLUDE /admin requests]

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


<http://www.zen-cart.com/forum/showthread.php?t=151606>

Also note; escaping is needed only in patterns, not in the literal target URL.

Online since 1995.

20 Apr 2010, 12:49 AM
#3
stuff4toys avatar

stuff4toys

Totally Zenned

Join Date:
May 2007
Location:
SW Florida
Posts:
1,062
Plugin Contributions:
1

Re: .htacess rewrite not working

Tried that and it isn't working. URL's like
http://www.ecabinetpro.com/index.php?main_page=index&cPath=2_90

Should redirect to
http://www.capecabinetdepot.com/index.php?main_page=index&cPath=2_90

I have

RewriteEngine on

Index Redirect for /index.php with no parameters

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

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

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

RewriteCond %{HTTP_HOST} ^ecabinetpros.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.ecabinetpros.com$
RewriteRule ^/?$ "http://www.capecabinetdepot.com/" [R=301,L]

Canonical Redirect non-blank, non-www and/or appended port number to www [EXCLUDE /admin requests]

RewriteCond %{HTTP_HOST} !^(www.ecabinetpro.com)?$
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule (.*) http://www.capecabinetdepot.com/$1 [R=301,L]

#Error Page
#ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
#ErrorDocument 401 /401.shtml
#ErrorDocument 400 /400.shtml
#ErrorDocument 500 /500.shtml
AddLanguage en .en # English

RewriteCond %{HTTP_HOST} ^ecabinetpro.com$ [OR]

RewriteCond %{HTTP_HOST} ^www.ecabinetpro.com$

RewriteRule ^/?$ "http://www.capecabinetdepot.com/" [R=301,L]

Even with the 404.shtml, all I get is "Link Broken"

Thanks for your advise
JOhn ><>

Newest Site: ChargerPros - Stuff4Toys

20 Apr 2010, 6:54 AM
#5
g1smd avatar

g1smd

Zen Follower

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

Re: .htacess rewrite not working

When I said> g1smd:

The first rule should be moved to be last. That rule could also be optimised by changing to:it meant to replace your code with the new code. You didn't do that. You have used both pieces of code and that is why it does not work. The new code never gets to run as the prior incorrect rule runs first. Delete the bit that is no longer needed.

Additionally, in that new replacement rule > Stuff4Toys:

RewriteCond %{HTTP_HOST} !^(www.ecabinetpro.com)?$should read ```
RewriteCond %{HTTP_HOST} !^(www.ecabinetdepot.com)?$


To be clear, delete the third and sixth block of code, and edit the fourth block.

Online since 1995.

20 Apr 2010, 12:40 PM
#6
stuff4toys avatar

stuff4toys

Totally Zenned

Join Date:
May 2007
Location:
SW Florida
Posts:
1,062
Plugin Contributions:
1

Re: .htacess rewrite not working

Thank You Thank You Thank You that works perfectly! If anyone is looking for this, here is the final code that workes perfectly.

 
RewriteEngine on
# Index Redirect for /index.php with no parameters
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [URL]http://www.capecabinetdepot.com/[/URL]? [R=301,L]
 
# Index Redirect for /(index.php)?main_page=index(&cPath=<blank>) URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index\.php)?$ [URL]http://www.capecabinetdepot.com/[/URL]? [R=301,L]
 
# Canonical Redirect non-blank, non-www and/or appended port number to www [EXCLUDE /admin requests]
RewriteCond %{HTTP_HOST}   !^(www\.capecabinetdepot\.com)?$
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule (.*) [URL]http://www.capecabinetdepot.com/$1[/URL] [R=301,L]
 
#Error Page
#ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
#ErrorDocument 401 /401.shtml
#ErrorDocument 400 /400.shtml
#ErrorDocument 500 /500.shtml
AddLanguage en .en # English 

Newest Site: ChargerPros - Stuff4Toys

20 Apr 2010, 9:14 PM
#7
g1smd avatar

g1smd

Zen Follower

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

Re: .htacess rewrite not working

Glad you're all fixed up!

This is server configuration code and it is very unforgiving of logic and/or coding errors.

Test very carefully. :smile:

Do make sure you change the name of your /admin folder and use that name in the code above. Do not tell anyone in the forum the real name of the admin folder.

Online since 1995.