Forum Moderators: phranque

Message Too Old, No Replies

Redirect 301 with RedirectMatch

         

fandangood

3:14 pm on Oct 2, 2006 (gmt 0)

10+ Year Member



I would like to redirect permanent from www.domain.com/dir/ to www.domain.com/dir/index.htm

I have tried with .htaccess:
Redirect permanent /dir/ [domain.com...] but this cause a infinity loop.

My server don't support RewriteRule but only Mod_alias. So I think that is possible with RedirectMatch. It is correct?
RedirectMatch permanent ^/dir/$ [domain.com...]

Thank you in advance for your suggestion.

jdMorgan

3:34 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If index.html is defined as the DirectoryIndex page, then this problem cannot be solved with mod_alias. Mod_rewrite is required, because it can test the URL as originally requested by the client to prevent a loop caused by interaction between the Redirect and DirectoryIndex directives.

A partial solution is to change the DirectoryIndex page (for example, to index.htm), and to rename that file. This avoids the looping problem, but requires the filename to be changed. Also, it will only 'fix' search engine listings if you do not link to /index.htm on your own site; You must always refer (link) to that page only as "/".

Jim

fandangood

4:14 pm on Oct 2, 2006 (gmt 0)

10+ Year Member



index.htm is defined as DirectoryIndex page

I have a lot of inbound link to www.domain.com/dir/ (PR 4) and a lot to www.domain.com/dir/index.htm (PR 5)
All internal link point at www.domain.com and www.domain.com/dir/index.htm (not any at www.domain.com/dir/ )
So I ask that it is correct for only "fix" search engine listings and possible duplicate content:
RedirectMatch permanent ^/dir/$ [domain.com...]

Thanks a lot for more suggestion

g1smd

9:32 pm on Oct 4, 2006 (gmt 0)

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



Google prefers to list URLs like www.domain.com/ and www.google.com/folder/ so I would do the redirect in the other direction and make sure that all internal pages of the site link back to www.domain.com/ too.

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/ [NC]
RewriteRule ^(.*)index.html?$ http://www.example.com/$1 [R=301,L]

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

This redirects both index.htm and index.html to "/" and the redirect preserves any folder names in the redirect path too.

Even better, If you ever change to index.php or something else, none of your existing links will be broken as the real name of the index file is never revealed in the internal linking.

fandangood

10:24 am on Oct 5, 2006 (gmt 0)

10+ Year Member



Thank you for reply but I can't use Rewrite engine (my server don't support) but only Redirect Match

The benifits are the same?

jdMorgan

4:58 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are limited to using RedirectMatch in .htaccess, without privileges to use it in httpd.conf, conf.d, etc., then you won't be able to use code to solve this problem at all.

Jim

fandangood

5:10 pm on Oct 5, 2006 (gmt 0)

10+ Year Member



but if I use RedirectMatch in .htaccess it's ok?

RedirectMatch permanent ^/dir/$ [domain.com...]