Welcome Guest, Not a member yet? Register   Sign In
url_rewrite to subdomain
#1

[eluser]danfreak[/eluser]
Hey guys,

I must rewrite with header [R=301] (namely redirect permanently) all my uri to say for exmple

Code:
http://www.mysite.com/example/any-file.php

to

Code:
http://example.mysite.com/any-file.php

Anyone has any suggestion about an .htaccess trick?

Dan
#2

[eluser]Michael Wales[/eluser]
Quote:RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^folder/(.*) http://folder.domain.com/$1 [R=301,L]

Not sure how to go about dynamically matching the condition but hopefully it gets you pointed in the right direction. This is just a google search result. Smile

http://www.webmasterworld.com/forum92/1763.htm
#3

[eluser]danfreak[/eluser]
cheers I'll try that out and I'll let you know!

I also found this great tutorial: .htaccess tips & tricks
#4

[eluser]Michael Wales[/eluser]
Thanks for the link - htaccess and regex is definitely something I need to work on.

Am I the only one that has to get some insane Googlefu and test 100 times before I get the right combination to work for me?
#5

[eluser]Michael Wales[/eluser]
Speaking of which - here's another link that has some great htaccess tips/tricks (plus many other things). I keep it in my Feed Reader:

http://www.askapache.com/
#6

[eluser]danfreak[/eluser]
Hey Michhael,

your rule works great but...

In the root directory I have the following .htaccess

Code:
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
</IfModule>

Namely the
Code:
RewriteCond %{REQUEST_FILENAME} !-d

tells "if a directory exists, don't do any rewrite"

I would like to tell:
Code:
if the directory exists but it is "example" (i.e. http://www.mysite.com/example/(anyUri)) redirect to http://example.mysite.com/(any-uri)

else (namely the directory don't exists) rewrite to index.php

Smile
#7

[eluser]Michael Wales[/eluser]
I believe mod_rewrite works from top to bottom, so just place the ruleset in the following order:

Quote:<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^folder/(.*) http://folder.domain.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
</IfModule>




Theme © iAndrew 2016 - Forum software by © MyBB