Forum Moderators: phranque

Message Too Old, No Replies

htaccess - subdomain to new subdomain

         

Asia_Expat

1:28 pm on Jul 17, 2006 (gmt 0)

10+ Year Member



I have 2 questions. Firstly, I recently lost my htaccess file because my host wrote over it with password protection and I didn't back up. I wrote it again but it's behaving slightly differently and I can't work out why.
Here's my current file...

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ h**p://www.mydomain.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ h**p://www.mydomain.com/ [R=301,L]
RewriteCond %{QUERY_STRING} .
RewriteRule ^index\.php$ /random_text.html? [L]

Before, all my index.php pages were being 301'd to / including the homepage and all sub directories... However, now I've written it from scratch, only the homepage is being rewritten.
How do I get it to redirect index.php to / for all directories.
In fact, I also want to do index.html as well.

My second question... I can't figure out how to redirect an old subdomain to a new one... there's plenty on how to redirect to a subdirectory but I can't find anything on redirecting to another subdomain. Is it the same method for redirecting www.foobar.com to www.barfoo.com?

Thanks ;-)

[edited by: Asia_Expat at 1:32 pm (utc) on July 17, 2006]

jdMorgan

5:39 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fix index problem:
[code]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(php¦html)\ HTTP/
RewriteRule ^([^/]+/)*index\.(php¦html)$ http://www.example.com/$1 [R=301,L]
[code]

> there's plenty on how to redirect to a subdirectory but I can't find anything on redirecting to another subdomain. Is it the same method for redirecting www.foobar.com to www.barfoo.com?

Yes, the same method used to *rewrite* a subdomain to a subdirectory can be modified to *redirect* one subdomain to another.

Change the broken pipe characters in the code above to solid pipes before use.

Jim

Asia_Expat

7:04 pm on Jul 17, 2006 (gmt 0)

10+ Year Member



Excellent... that works a treat :-)

I'm curious though... and I'm sure it's a daft question but why did you post with broken pipes when they should be solid?
Here's mine now...

[code]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(php¦html)\ HTTP/
RewriteRule ^([^/]+/)*index\.(php¦html)$ h**p://www.umpa-lumpa.com/$1 [R=301,L]
[code]

Edit: Oh, now I see why LOL

[edited by: Asia_Expat at 7:05 pm (utc) on July 17, 2006]

jdMorgan

11:22 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, but why did *you* post with broken pipes, eh?

(The forum software modifies them, and often drops spaces that are required, too.)

Jim