Forum Moderators: phranque

Message Too Old, No Replies

htaccess subdomain to url

         

pennywaltz

6:06 pm on Jul 1, 2010 (gmt 0)

10+ Year Member



I'm fairly new to htaccess. I can't seem to figure out how to configure subdomain to redirect url.

Can someone show me?

I tried the 301 one, but i think that's for folders only.

g1smd

6:29 pm on Jul 1, 2010 (gmt 0)

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



If it's a redirect it will always return a 301 or 302 status code.

What code have you tried? There's tens of thousands of examples of redirects in prior threads.

pennywaltz

6:54 pm on Jul 1, 2010 (gmt 0)

10+ Year Member



This is the code i wrote. I am very very new to htaccess.

RewriteCond %{HTTP_HOST} calendar.example.com [NC]
RewriteRule ^(.*) http://www.google.com/calendar/embed?src=tanpiphone@gmail.com&ctz=America/New_York$1 [R=301,L]

sadly it didn't work :(

[edited by: jdMorgan at 2:46 pm (utc) on Jul 13, 2010]
[edit reason] example.com [/edit]

g1smd

9:39 pm on Jul 1, 2010 (gmt 0)

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



You'd also need
RewriteEngine On
ahead of that.

Don't forget to also escape the literal periods in the pattern.

pennywaltz

12:59 am on Jul 2, 2010 (gmt 0)

10+ Year Member



oh rewrite engine is there, you only need one for the whole thing right?

This is the whole .htaccess file. It's pretty long so i figure i would only include the lines regarding the subdomain :)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#
Redirect 301 /stats http://my.statcounter.com/project/standard/stats.php?project_id=5710647&PHPSESSID=98b06a04c979d0d17dd11769015ce6f6
Redirect 301 /Dashboard http://example.com/wordpress/wp-admin/
Redirect 301 /stats1 https://www.google.com/analytics/settings/home?scid=15294742
Redirect 301 /docs https://www.google.com/a/example.com/ServiceLogin?continue=http%3A%2F%2Fdocs.google.com%2Fa%2Fexample.com%2F&service=writely&ul=1
Redirect 301 /old http://pennytest.otherexample.com/
Redirect 301 /control https://www.google.com/a/example.com/ServiceLogin?service=CPanel&passive=1209600&continue=https%3A%2F%2Fwww.google.com%2Fa%2Fcpanel%2Fexample.com%2FDashboard&followup=https%3A%2F%2Fwww.google.com%2Fa%2Fcpanel%2Fexample.com%2FDashboard
Redirect 301 /mail https://www.google.com/a/example.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fa%2Fexample.com%2F&bsv=1eic6yu9oa4y3&ltmpl=default&ltmplcache=2
Redirect 301 /calendar1 http://www.google.com/calendar/hosted/example.com
Redirect 301 /sites http://sites.google.com/a/example.com
Redirect 301 /wordpress/wp-content/plugins/disqus-comment-system/xd_receiver.htm http://www.example.com/xd_receiver.htm
#
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} calendar.example.com [NC]
RewriteRule ^(.*) http://www.google.com/calendar/embed?src=example@gmail.com&ctz=America/New_York$1 [R=301,L]
#
</IfModule>

[edited by: jdMorgan at 2:49 pm (utc) on Jul 13, 2010]
[edit reason] example.com [/edit]

angle333

8:06 pm on Jul 2, 2010 (gmt 0)

10+ Year Member



i don't know about doing this with htaccess, but in PHP its pretty easy.

Grab subdirectory, append to front of url, redirect to that new url.

[edited by: tedster at 6:20 am (utc) on Jul 3, 2010]

jdMorgan

1:51 am on Jul 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're mixing RewriteRule with Redirect directives -- not recommended.

Use RewriteRule for all of your redirects.
Put all redirect rules (the ones with [R=] flags) ahead of all internal rewrites (your WP code should be last.)

Jim

pennywaltz

6:06 am on Jul 13, 2010 (gmt 0)

10+ Year Member



so for each one i have to do a rewrite cond and rewrite rule?
So for example for my first redirect:

RewriteCond %{HTTP_HOST} www\.tan-pham\.com\stats [NC]
RewriteRule ^(.*) [http://www.webmasterworld.com/redirect.cgi?f=92&d=4162909&url=http://my.statcounter.com/project/standard/stats.php?project_id=5710647&PHPSESSID=98b06a04c979d0d17dd11769015ce6f6] [R=301,L]

and then copy and paste taht again but do it for the next redirect?

Can you suggest some recommended tutorials for this and .htaccess? I'm very very new at this.

jdMorgan

3:24 pm on Jul 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, usually all you have to do is change
 Redirect 301 /x y 

to
 RewriteRule ^x y [R=301,L] 

and then move all RewriteRules with [R=] ahead of all rules without [R=]

The general rule of thumb to prevent unintended consequences such as malfunction or exposing internal filepaths as URLs to search engines (messing up your search listings) is to put all external redirects first, ordered from most specific patterns and conditions (fewest URLs affected) to least-specific patterns and conditions (more URLs affected), followed by all internal rewrites, again in order from most- to least-specific. Access control rules, if any, should be placed before the redirects.

The links to resources posted in our Apache Forum Charter and the examples and tutorials in our Apache Forum Library may prove useful. See the links to these resources at the top of this page.

Jim