1

I have a specific need:

example.com/store/{location} must redirect to example.com/store2/{location}

And this needs to redirect, not just a url 'rewrite', so I'm guessing I need mod_alias, right? Anyone care to share the correct code for it? I'm a little fuzzy with both mod_rewrite and mod_alias. (I hope I asked this correctly) Thanks!!

spadeworkers
  • 375
  • 3
  • 11

2 Answers2

2

If you mean you want to tell the browser to redirect its location, you simply can do this with mod_alias:

Redirect /store http://example.com/store2

Or the following if you mean it's a permanent redirect:

RedirectPermanent /store http://example.com/store2

As for your confusion, mod_alias is basically a simpler version of mod_rewrite. Quoting GreyWyvern:

Essentially, if you're doing a "rewrite" which doesn't have any complex conditions attached to it, you should be using mod_alias. Conversely, if you want to redirect requests to files and query strings which you don't want displayed in the browser's address bar, you should be using mod_rewrite

cregox
  • 17,674
  • 15
  • 85
  • 116
1
RewriteRule ^/store/(.*)/$ store2/$1 [R=301,L]
David Fells
  • 6,678
  • 1
  • 22
  • 34
  • Strip the trailing `/` in case the user doesn't write it. And BTW @spadeworkers this is mod_rewrite – M'vy Apr 28 '11 at 07:37
  • This didn't work. I had the following code in the .htaccess residing inside the store directory: RewriteEngine on RewriteRule ^/store/(.*)/$ store2/$1 [R=301,L] No errors or anything, it just simply didn't redirect. – spadeworkers Apr 28 '11 at 19:07
  • And I did try removing the trailing slash too – spadeworkers Apr 28 '11 at 19:10
  • I believe `RewriteRule ^/store(.*)$ http://example.com/store2$1 [R=301,L]` should work basically the same way as what I've suggested, and `301` can be replaced by `permanent` here as well. – cregox May 03 '11 at 04:54