Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect just one directory

         

7miles

5:07 pm on Oct 26, 2008 (gmt 0)

10+ Year Member



Hi,
I'm having troubles with redirects.

I am using these commands:

<Files ~ "^.(htaccess¦htpasswd)$">
deny from all
</Files>
Redirect permanent /folder/category/postname.html http://newdomain.com/folder/category/postname.html
Redirect permanent /folder/category/postname2.html http://newdomain.com/folder/category/postname2.html
Redirect permanent /folder/category2/postname.html http://newdomain.com/folder/category2/postname.html
order deny,allow

It's working good but if I use same command to redirect:

 Redirect permanent /folder http://newdomain.com/folder 

I lose all the rest commands.

How to redirect also the main page of /folder without interfere with other redirects ?

g1smd

6:30 pm on Oct 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is that rule placed last, so that the others take precedence?

If it is first, it will match all requests and redirect for all requests.

Is the target on the same domain, or a different domain?

If it is the same domain, you'll be better off using RewriteRule for all the rules (instead of Redirect), as it will give you more control on pattern matching.

jdMorgan

7:23 pm on Oct 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Redirect directive redirects any URL that starts with the specified string on the left to the URL on the right, plus any further URL-path-part requested by the client, but not specified on the left.

So, a directive such as

 Redirect permanent /folder http://newdomain.com/folder 

will redirect
/folder to newdomain.com/folder -and-
/folder/ to newdomain.com/folder/ -and-
/folder/<anything-at-all> to newdomain/<anything-at-all>

If you want to redirect /folder and only /folder, then use RedirectMatch, and be very careful that you understand the regular-expressions pattern-matching that it uses. See the tutorial in our Forum Charter if you need more info.

Jim

7miles

7:35 pm on Oct 26, 2008 (gmt 0)

10+ Year Member



thx for your replies guys

I know I can redirect the hompage only using this command:

 redirectMatch 301 ^/$ http://newdomain.com/ 

but I am not able to use that command for /folder, sorry I am very newbie at apache stuff.

I tried

 ^/folder 
but it does not work.
Any help please ?

7miles

7:59 pm on Oct 26, 2008 (gmt 0)

10+ Year Member



I solved with this command:
 RedirectMatch 301 ^/folder/$ http://newdomain.com/ 

This way permits me to redirect /folder but keep alive for example: folder/postname/