Help - Search - Members - Calendar
Full Version: change domain name using mod_rewrite
OpenSourcePhoto > World Wide Web > Website Stuff
Adam Squier
I've successfully transferred my Web sites to a different host. Woo Hoo! Finally figured out how to get the .htaccess to work on sub domains, but that was the earlier part of the evening.

Now, here's what I can't figure out (and the new host says they don't support this but I can figure out how to do it on my own -- thanks!):

Our domain name is squierphotography.com -- simple enough, right?

The problem is that we have a weird spelling of our last name. So I got squirephotography.com at the same time several years ago.

What I want to happen is whenever someone asks for squirephotography.com (the wrong spelling) I want them to be directed to squierphotography.com (the correct spelling).

Right now all the content is correct on the wrong spelling, but the URL isn't changing to the correct spelling.

If anyone here knows how to get this to work using an .htaccess file using mod_rewrite, I'd love to know.

And if you don't understand anything I've written above, that's OK, too. smile.gif
kaitlin
Check out this tutorial, and the forcing new requests section, which will change the URL, and force the page to reload...might be some other useful info, too.

http://www.yourhtmlsource.com/sitemanageme...lrewriting.html

...might not be exactly what you're looking for....but looks like it will do what you want.
Adam Squier
QUOTE(kaitlin @ January 29 2007, 09:55 PM) [snapback]64971[/snapback]
Check out this tutorial, and the forcing new requests section, which will change the URL, and force the page to reload...might be some other useful info, too.

http://www.yourhtmlsource.com/sitemanageme...lrewriting.html

I've looked at that page a lot this evening and I couldn't figure out a way to change the domain name. The rest of the URL, yes, but not the domain name. I'll look again, though. Thanks.
kaitlin
ahhh......can you post up what you've got in that htaccess file now for the rewrite??
Adam Squier
I don't have anything in there right now for that. I couldn't find how to do it. But I'll show you what I do have right now. Nothing very exciting, really.
[codebox]AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
AddHandler server-parsed .inc
Options Indexes FollowSymLinks IncludesNoExec
Options -Indexes

ErrorDocument 400 /errors/400badrequest.html
ErrorDocument 401 /errors/401authreq.html
ErrorDocument 403 /errors/403forbidden.html
ErrorDocument 404 /errors/404notfound.html
ErrorDocument 500 /errors/500internalerror.html


redirect /people/ http://www.squierphotography.com/families/
redirect /places/ http://www.squierphotography.com/other/
redirect /things/ http://www.squierphotography.com/other/

# These are old places for these slideshows
redirect /CaseyQuinn/ http://www.squierphotography.com/slideshows/CaseyQuinn/
redirect /Dalton/ http://www.squierphotography.com/slideshows/Dalton/
redirect /Dearing/ http://www.squierphotography.com/slideshows/Dearing/
redirect /KimBrettEngagement/ http://www.squierphotography.com/slideshow...rettEngagement/
redirect /kellyShannon/ http://www.squierphotography.com/slideshows/kellyShannon/
redirect /Owen/ http://www.squierphotography.com/slideshows/Owen/
redirect /owen6mos/ http://www.squierphotography.com/slideshows/owen6mos/
redirect /ruby/ http://www.squierphotography.com/slideshows/ruby/
redirect /SarahMichaela/ http://www.squierphotography.com/slideshows/SarahMichaela/
redirect /SCCGrandOpening/ http://www.squierphotography.com/slideshows/SCCGrandOpening/
redirect /SCCHayride/ http://www.squierphotography.com/slideshows/SCCHayride/
redirect /smorgasbord/ http://www.squierphotography.com/slideshows/smorgasbord/[/codebox]
Jillian Kay
where did you buy the domain names from?

i get all mine at godaddy.com, and they have free forwarding (so i don't even have to touch htaccess). if you aren't with them, then i guess that's a pretty crappy answer. unsure.gif
kaitlin
Also, who is your web-host, and where are your domains registered???

I ask because you might be able to effect what you are talking about in another fashion, even though they said they don't support it....

QUOTE(Jillian Kay @ January 29 2007, 10:06 PM) [snapback]64980[/snapback]
where did you buy the domain names from?

i get all mine at godaddy.com, and they have free forwarding (so i don't even have to touch htaccess). if you aren't with them, then i guess that's a pretty crappy answer. unsure.gif



GoDaddy, and there are a few others that allow it (although I found out today that my place offers only some of these things if you're not hosting with them, too, which is kinda crappy)
Adam Squier
I just transferred from lamphost.net over to westhost.com. The registration is in the process of being transferred. Should be done in a couple days.

At lamphost.net they just did what I asked for. Pre-sales at westhost said they could do it, but I wouldn't be able to do it on my own with their online tools -- I'd have to ask them to do it. Earlier today I was told it wasn't supported and I'd need to use mod_rewrite in an .htaccess file. Aaargh!

Incidentally, I'm doing another redirect from columbusbabyphotographer.com over to squierphotography.com and it's working the way I want it to (or will, once the DNSs get updated). Keeping columbusbabyphotographer.com in the address bar.

The difference is that I want the domain name to change from the wrong spelling to the right one in the previous example.

QUOTE(Erik Dungan @ January 29 2007, 10:11 PM) [snapback]64984[/snapback]
iirc, mod_rewrite doesn't change the domain in the address of the visitor's browser. it's more of a server-side thing.

if your host supports PHP, you can use change your default page to index.php (if its not already) and put the following code in the top of the page:

<?
if (strpos($_SERVER["SERVER_NAME"], "squire") !== false) {
header("Location:http://www.squierphotography.com");
}
?>

Basically, this will look at the current domain and, if it contains the string "squire", it will redirect to squierphotography.com

That might do it ...

Any way to do this using DHTML? As you can see from my .htaccess file above, that's what I'm using. For the new site, I'll probably use PHP for the stuff I'm using DHTML for, but that won't happen for a while.
kaitlin
Adam,
Try using the request to reload - honestly, it's been awhile, but see if this works.

Put this code into your htaccess file:
CODE
RewriteEngine on
RewriteRule ^(.*) http://squierphotography.com [R]
Adam Squier
QUOTE(kaitlin @ January 29 2007, 10:29 PM) [snapback]65001[/snapback]
Adam,
Try using the request to reload - honestly, it's been awhile, but see if this works.

Put this code into your htaccess file:
CODE
RewriteEngine on
RewriteRule ^(.*) http://squierphotography.com [R]

That didn't quite work. Got an error from Firefox that the server was trying to redirect in a way that would never work, but it looks like we're getting close.

Thanks for everyone's help.

I do have access to the httpd.conf file, if there's a better way to do it from there.
Adam Squier
OK, I'm a dweeb. I spent all day trying to get the include files to work using .htaccess (parsing the html files as shtml files) and now I see I can make it all work in the httpd.conf file. Oh well. Next time I'll know better.

I'm still playing around with the rewrite stuff, though.
MattA
Just a quick Q but why couldn't you just do a redirect in the html? Maybe that's dumb - I dunno. lol
Adam Squier
QUOTE(Matt Antonino @ January 29 2007, 10:54 PM) [snapback]65024[/snapback]
Just a quick Q but why couldn't you just do a redirect in the html? Maybe that's dumb - I dunno. lol

Well, for one thing, that's not as elegant as the server doing it. thumbsup.gif

But anyway, it's not going to a different file -- it's the same file, so it would be redirecting to itself, and end up doing that over and over until something snapped. Which might be fun to watch.
Adam Squier
Here's something from the httpd.conf file that might be useful:

[codebox]<VirtualHost *>
ServerName squirephotography.com
ServerAlias www.squirephotography.com
DocumentRoot /var/www/html
</VirtualHost>[/codebox]

I tried changing the ServerAlias to the right spelling, and then restarting the server, but it didn't seem to do anything.

It's about time for bed so I'll continue this in the morning. Or just ask them to fix it.

I really appreciate all the help everyone's given me. Thanks!!
kaitlin
Probably not working if you've got a second redirect in there somewhere putting everything from squire to point to files at squier. You may need to remove some of the redirects after that initial one. I would try one thing at a time in the htaccess to try to pinpoint your problem.
Ben Vigil
QUOTE(Adam Squier @ January 29 2007, 11:15 PM) [snapback]65046[/snapback]
Here's something from the httpd.conf file that might be useful:

[codebox]<VirtualHost *>
ServerName squirephotography.com
ServerAlias www.squirephotography.com
DocumentRoot /var/www/html
</VirtualHost>[/codebox]

I tried changing the ServerAlias to the right spelling, and then restarting the server, but it didn't seem to do anything.

It's about time for bed so I'll continue this in the morning. Or just ask them to fix it.

I really appreciate all the help everyone's given me. Thanks!!

Adam,

Dungan's way will work as desired and will redirect the browser and change the URL and all that stuff just like mod-rewrite. From the browsers' prospective, they are the same. The only difference is that mod_rewrite sends a "Location:" header to the browser from within the apache code, and Dungan's way sends a "Location:" header from within the php engine. Same diff. Anyway...

Your <virtualhost > settings are not going to affect what you are trying to do.

Kaitlin's code should work assuming that a) the mod-rewrite module is loaded and b) both domains are NOT pointed to the same virtual host in apache.

If both domains are handled by the same virtualhost config, her code will loop. Her code says, match anything and redirect to the correct site. If they are the same codebase, it will loop indefinitely. This is probably what Firefox was telling you. So modify it like so...

CODE
RewriteEngine on
RewriteRule ^.*squire.* http://squierphotography.com [R]


You can also add the [L] to tell mod-rewrite to make this the Last rule (i.e. skip the rest).

CODE
RewriteEngine on
RewriteRule ^.*squire.* http://squierphotography.com [L,R]


The regex code above may not be perfect, but it's close.
Adam Squier
Hi Ben. That didn't seem to do anything. I'm adding that to the .htaccess file, right? I tried playing around with it a little, but nothing I did made a difference. Thanks for your help.
Jules
Adam,
Once you figure all this out, you need to send a letter to Westhost sales and let them know how much time it took you to figure out something the sales department said was supported, but then wasn't on the tech side. They should give you a discount or something. Just my opinion. I'm with Westhost too. They claim to have really great support, though I've not needed anything so far.

Good luck. I hope you figure this out soon!
Adam Squier
OK, tech support helped me out. He did me a favor as it's not "officially" supported and wanted to know who I talked to in pre-sales but of course I don't know. But it works. I had to put it into the .htaccess file, which is fine. Here's how it looks:

[codebox]Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^squirephotography.com [nc]
rewriterule ^(.*)$ http://www.squierphotography.com/$1 [r=301,nc]
rewritecond %{http_host} ^www.squirephotography.com [nc]
rewriterule ^(.*)$ http://www.squierphotography.com/$1 [r=301,nc][/codebox]

Just in case anyone else ever wants to do this, too.
Ben Vigil
QUOTE(Adam Squier @ January 30 2007, 04:49 PM) [snapback]65602[/snapback]
OK, tech support helped me out. He did me a favor as it's not "officially" supported and wanted to know who I talked to in pre-sales but of course I don't know. But it works. I had to put it into the .htaccess file, which is fine. Here's how it looks:

[codebox]Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^squirephotography.com [nc]
rewriterule ^(.*)$ http://www.squierphotography.com/$1 [r=301,nc]
rewritecond %{http_host} ^www.squirephotography.com [nc]
rewriterule ^(.*)$ http://www.squierphotography.com/$1 [r=301,nc][/codebox]

Just in case anyone else ever wants to do this, too.

Yep, that's right. I forgot that you don't have access to the host name from within the RewriteRule directive, just the part of the URL after the domain name.

Anyway, glad you got it working.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.