homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Help with .htaccess redirect

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

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.


http_://12.456.78.90/subfolder1/product1.html OR





 10:31 am on Dec 16, 2010 (gmt 0)

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)

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)

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

This code will work only if placed in the root .htaccess at 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)

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}.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved