Forum Moderators: phranque

Message Too Old, No Replies

Redirect .htaccess

         

BrentXDR

9:40 pm on Jan 26, 2011 (gmt 0)

10+ Year Member



I am trying to use a .htaccess file to redirect the follwoing:

[mydata.example.com...] & [mydata.example.com...]
to
[mydata.example.com...]

I have tried numerous redirects with no luck, any information or help would be greatly appreciated.

Thank you.

g1smd

10:20 pm on Jan 26, 2011 (gmt 0)

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



What have you tried so far?

It should be two simple lines of code, and there are literally thousands of previous threads in this forum with redirect code within.

BrentXDR

2:27 am on Jan 27, 2011 (gmt 0)

10+ Year Member



Yeah there is tons of threads/topics about this.. I guess im just not grasping the concept. I'll eventually figure it out.

Thanks.

g1smd

8:25 pm on Jan 27, 2011 (gmt 0)

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



Post some code, ask specific questions about it and we can get started.

BrentXDR

2:02 am on Jan 28, 2011 (gmt 0)

10+ Year Member



Ok thanks,

I have been referencing to this thread: [webmasterworld.com...]

of course the first line will be:
RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^contact [secure.example.com...] [R=301,L]

^contact can you please explain this? is that looking for the word "contact" in the url, then if found redirect to [secure.example.com...]

Im trying to completely understand because I believe what Im wanting to do is very similiar to the above thread.

Im really sorry, just trying to learn. (definitely not my day job) haha

Thanks

g1smd

6:57 pm on Jan 28, 2011 (gmt 0)

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



It looks for a request that begins with "contact" at the start of the path part of the URL.

BrentXDR

8:08 pm on Jan 28, 2011 (gmt 0)

10+ Year Member



So with my 2 examples:
[mydata.example.com...] & [mydata.example.com...]

Do I need to have my code to look for "mydata" then redirect to:
[mydata.example.com...]

Since I want to redirect everything to https I should not have to look for anything specific though, correct? Im sure there is some type of code that will redirect everything to [mydata.example.com...] without looking for anything specific in the url.

g1smd

8:21 pm on Jan 28, 2011 (gmt 0)

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



If you want to look for "mydata", then you'll need a RewriteCond looking at HTTP_HOST.

RewriteRule patterns can only match the path part of a URL request. You need a RewriteCond to look at any other part: host name, port, query string, etc.

When redirecting to HTTPS, you'll need a RewriteCond to test SERVER_PORT and make sure it is NOT 443. You can then redirect those requests to HTTPS. If you don't test SERVER_PORT you'll have an infinite loop.

[edited by: g1smd at 8:58 pm (utc) on Jan 28, 2011]

BrentXDR

8:38 pm on Jan 28, 2011 (gmt 0)

10+ Year Member



I think I may have a problem with my setup as well.

can you pm me and let me explain?

jdMorgan

10:52 pm on Jan 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We don't encourage off-line conversations here, as it takes away the usefulness of the thread for future readers... You are of course free to contract-out the work as you see fit, but on your own initiative.

This trivial bit of code

RewriteCond %{HTTP_HOST} ^(www\.)?mydata.(www\.)?example\.com
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L]

redirects requests for all pages and resources in mydata.example.com or www.mydata.example.com or mydata.www.example.com or www.mydata.www.example.com to the same pages and resources on [secure.example.com...]

Jim