Wildcard redirect subdirectory to subdomain?

Discuss practical ways rearrange URLs using mod_rewrite.

Wildcard redirect subdirectory to subdomain?

Postby thripp » Mon Jul 07, 2008 1:17 pm

Hello,

I'm trying to redirect addresses at http://richardxthripp.com/richardxthripp$ to http://richardxthripp.thripp.com$, where $ is a wildcard. So far I have this:

Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?richardxthripp\.com
RewriteRule ([a-z0-9-]+)/? http://$1.thripp.com [R=301,NC,L]


... but it always redirects to richardxthripp.thripp.com. How can I change this so it keeps the tail end of the URL?

Thanks,
Richard
thripp
 
Posts: 3
Joined: Mon Jul 07, 2008 1:14 pm

Postby richardk » Mon Jul 07, 2008 2:01 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?richardxthripp\.com$ [NC]
RewriteRule ^richardxthripp(/(.*))?$ http://richardxthripp.thripp.com/$2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby thripp » Tue Jul 08, 2008 2:12 am

Thank you very much, richardk! That did the trick. I hope to never change my website address again. :)

Here's an example for anyone else reading: http://richardxthripp.com/richardxthripp/gallery goes to http://richardxthripp.thripp.com/gallery automatically now.
thripp
 
Posts: 3
Joined: Mon Jul 07, 2008 1:14 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 99 guests

cron