Welcome to WebmasterWorld Guest from 54.162.121.80
Forum Moderators: Ocean10000 & incrediBILL & phranque
Something like
RewriteCond %{HTTP_HOST} ^123.123.123.123/sub_dir/*
RewriteRule ^(.+) http://www.example.com/sub_dir/same_final_dest_requested$1 [L,R=301]
I know the syntax is whacked...I'm not the sharpest tool in the drawer on mod_rewrite. Is what I'm asking about possible with mod_rewrite?
Thanks,
Dave
[edited by: jdMorgan at 3:43 pm (utc) on Jan. 24, 2007]
[edit reason] example.com [/edit]
Yes, but you're quite close.
> Is what I'm asking about possible with mod_rewrite?
Five examples:
In example.com/.htaccess:
RewriteCond %{HTTP_HOST} ^123\.123\.123\.123
RewriteRule ^sub_dir/(.*)$ http://www.example.com/sub_dir/$1 [R=301,L]
This does the IP redirect only for the /sub_dir/ subdirectory In example.com/sub_dir/.htaccess:
RewriteCond %{HTTP_HOST} ^123\.123\.123\.123
RewriteRule (.*) http://www.example.com/sub_dir/$1 [R=301,L]
Because of the .htaccess file's location, this does the IP redirect only for the /sub_dir/ subdirectory In example.com/.htaccess:
RewriteCond %{HTTP_HOST} ^123\.123\.123\.123
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This does the IP redirect for *all* resources in the domain. In example.com/.htaccess:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This redirects requests for *anything except* the proper domain and for *all* resources in the domain. In example.com/httpd.conf
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule [b]^/([/b].*)$ http://www.example.com/$1 [R=301,L]
Same as above, showing necessary change for use in httpd.conf or conf.d In example.com/httpd.conf
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.co[b]m$1[/b] [R=301,L]
Same as above, showing alternate change for use in httpd.conf or conf.d For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
RewriteCond %{HTTP_HOST} ^123\.123\.123\.123
RewriteRule (.*) http://www.example.com/sub_dir/$1 [R=301,L]
...was EXACTLY what I needed. It worked perfectly, a quick server header check shows a 301 for the IP version of the URL, and hopefully will keep Google smiling down on me. :-)
Dave