Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite Question

         

Gian04

5:47 am on Aug 9, 2007 (gmt 0)

10+ Year Member



How can I make it that if a visitor type http://example.com it will redirect to http://www.example.com

and the same manner if he type http://www.example.com/index.php or http://example.com/index.php it will redirect to http://www.example.com

ahmedtheking

8:38 am on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well for your first question:

RewriteRule (.*)$ http://www.example.com$1 [R=301]

And for the second one
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

Gian04

12:22 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



Will this one redirect all request to www.example.com?

RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

If the user typed any of the following
http://www.example.com/index.php
http://www.example.com/dir/index.php
http://www.example.com/dir2/index.php
http://www.example.com/dir1/abc/index.php

ahmedtheking

12:45 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule .*index\.php$ http://www.example.com/

[edited by: jatar_k at 2:31 pm (utc) on Aug. 9, 2007]
[edit reason] typo [/edit]

g1smd

4:23 pm on Aug 9, 2007 (gmt 0)

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



These two rules avoid any redirection chain.

# Fix only index files to "/", and force www for those at the same time.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.(html?¦php¦asp¦cfm)\ HTTP/
RewriteRule ^(.*)index\.(html?¦php¦asp¦cfm)$ http://www.domain.com/$1 [R=301,L]

# Force www for all other non-index URLs.
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

jdMorgan

5:03 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace all broken pipe "¦" characters in the code above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim