Welcome to WebmasterWorld Guest from 54.198.87.238

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help with .htaccess redirect

     
6:04 am on Dec 16, 2010 (gmt 0)

10+ Year Member



Hi guys, i am looking to redirect my users who come through my sever Ip, to another domain. There is always a sub folder in the original url, in this case subfolder1. However, there is no set standard to product1.html as it might change to search.php?product=23 or other files...etc. Also would like the redirect to be a permanent redirect 301. Thanks for all your help.

Example:

http_://12.456.78.90/subfolder1/product1.html OR
http_://12.456.78.90/subfolder1/search.php?product=23..etc

to

http_://www.newsitedomain.com/product1.html
http_://www.newsitedomain.com/search.php?product=23..etc
10:31 am on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Please present your code as a basis for discussion.

Please read and fully understand [webmasterworld.com...] before proceeding.
4:16 pm on Dec 16, 2010 (gmt 0)

10+ Year Member



Hi g1smd,
i got this far, not sure if it is right.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^12\.456\.78\.90
RewriteRule ^subfolder1(.*)$ http_://www.newsitedomain.com/$1 [R=301,L]
4:41 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You want it so that if user requests 12.34.56.78/folder1/<somepage> they are redirected to www.example.com/<somepage> ?

This code will work only if placed in the root .htaccess at 12.34.56.78/.htaccess file.

For use in the server configuration file, you will need a leading slash on the start of the RewriteRule pattern.

If the code is going in the .htaccess file inside folder1, folder1 should not appear in the RewriteRule pattern as it is stripped from the request before mod_rewrite is invoked.

[edited by: g1smd at 5:18 pm (utc) on Dec 16, 2010]

5:08 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Please keep your example code in strict compliance with your original filespace-organization and URL examples, or re-state them along with your new code. Also, as implied by the above, it's a very good idea to state *where* you are installing this code, as the requirements will vary based on config file location.

The current rule handles only the "http_://12.456.78.90/subfolder1/product1.html" bad-URL case. Once we get that sorted, we can go on to the other bad format of "http_://12.456.78.90/subfolder1/search.php?product=23..etc ", which will require an additional rewritecond to examine %{QUERY_STRING}.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month