homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
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
BlackRaven




msg:4242987
 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.

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

 

g1smd




msg:4243039
 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.

BlackRaven




msg:4243177
 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]

g1smd




msg:4243201
 4:41 pm on Dec 16, 2010 (gmt 0)

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]

jdMorgan




msg:4243218
 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}.

Jim

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