Zen Cart Logo
Forums / General Questions / .htaccess redirect

.htaccess redirect

Locked

Views: 3,035

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
12 Mar 2010, 8:53 AM
#1
damiantaylor avatar

damiantaylor

Zen Follower

Join Date:
Aug 2009
Posts:
244
Plugin Contributions:
0

.htaccess redirect

Hi all!

I'm hoping someone can give me some help with .htaccess because I'm really struggling.
I have my Zen Cart store located in a subdirectory so I'd like to redirect to the subdirectory when someone enters the main URI in to the browser.

My Zen Cart is located in a subdirectory called /shop so I need to redirect https://www.mywebsite.co.uk to https://www.mywebsite.co.uk/shop.
The reason I have it in a subdirectory is because in the future there will be a 'service' section to the website which I will be putting in a subdirectory called /service.

In addition, I'd like to hide the subdirectory name from the browser too, if that's possible!

To summarise, when someone enters https://www.mywebsite.co.uk in the their browser, I'd like to redirect to https://www.mywebsite.co.uk/shop but the browser address bar should only show https://www.mywebsite.co.uk.

I don't even know if what I want to do is possible, but if someone could let me know either way I'd really appreciate it

:)

12 Mar 2010, 9:25 AM
#2
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,284
Plugin Contributions:
38

Re: .htaccess redirect

Adding a future directory to the site is no reason NOT to have your Zen Cart in the root as it should be.

Note that you are not permitted to "hide" the directory path as you asked. This is called cloaking and it will get you a Google penalty.

~Melanie

12 Mar 2010, 9:57 AM
#3
damiantaylor avatar

damiantaylor

Zen Follower

Join Date:
Aug 2009
Posts:
244
Plugin Contributions:
0

Re: .htaccess redirect

Thanks Melanie,
I'll move it to the root.
I've found a tutorial that shows me how.

I had a feeling it wasn't the way to do it :)

12 Mar 2010, 10:26 AM
#4
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,284
Plugin Contributions:
38

Re: .htaccess redirect

Cheers

~Melanie

19 Mar 2010, 9:21 PM
#5
kuzman05 avatar

kuzman05

New Zenner

Join Date:
Mar 2010
Posts:
2
Plugin Contributions:
0

Re: .htaccess redirect

I've got issue with zencart redirects. In short: zencart resides on https://www.site.com/shop and I want to move it to just https://www.site.com. Currently anybody hitting https://www.site.com will be forwarded to /shop folder where the cart is. Because I have lot of inbound links to /shop pages I want all of those to be 301 redirected to their counter parts on https://www.site.com where i copied the entire cart. I've played with many combinations in .htaccess in both the webroot and /shop folder but nothing got me what I needed. Any insights/advice? Here is the current .htaccess in /shop folder

BOF SSU

Options +FollowSymLinks -MultiViews
RewriteEngine On

Make sure to change "test_site" to the subfolder you install ZC. If you use root folder, change to: RewriteBase /

RewriteBase /

Deny access from .htaccess

RewriteRule ^.htaccess$ - [F]

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^(.*) index.php?/$1 [E=VAR1:$1,QSA,L]

EOF SSU

20 Mar 2010, 1:56 AM
#6
iray avatar

iray

New Zenner

Join Date:
Jun 2007
Posts:
72
Plugin Contributions:
0

Re: .htaccess redirect

All you need is to add following code after RewriteBase line:

RewriteRule ^/shop/(.*)$ http://www.site.com/$1 [R=301,QSA,L]
11 Apr 2010, 12:09 AM
#7
g1smd avatar

g1smd

Zen Follower

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

Re: .htaccess redirect

Paths are localised when used with ModRewrite in .htaccess so the leading slash will not be there.

Additionally, QSA is the default action and does not need to be mentioned. This would work:```
RewriteRule ^shop/(.*) http://www.example.com/$1 [R=301,L]




For efficiency, I'd modify it a bit more, and put the code in the /shop/ folder, so it is only parsed when the URL request actually contains /shop/ within. In that case the code would be:```
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
```The above code MUST go in the /shop/ folder. In root it will cause an infinite loop.

See also post #11 at <http://www.zen-cart.com/forum/showthread.php?t=150620&page=2>