user3728949
user3728949

Reputation:

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL: http://www.myWebsite.com/bananas

to: http://www.myWebsite.com/fruits/bananas

I cant test it because I'm sending this to somebody.

I have these but I don't know for sure which one works:

RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1





Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]

Upvotes: 0

Views: 40

Answers (2)

lisa p.
lisa p.

Reputation: 2158

Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.

  1. Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)

  2. Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content) http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.

Checkout this as a guide: http://www.htaccessredirect.net/

Upvotes: 1

Gonçalo Ribeiro
Gonçalo Ribeiro

Reputation: 216

I believe you are looking for

Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas

The HTTP 301 stands for Moved Permanently.

I haven't tested it, though.

Upvotes: 0

Related Questions