MSWD
April 13, 2010, 1:26am
1
Can anyone help me? We have moved from beaconelectricalservice.com to prolectricllc.com . I want to write a 301 redirect in my htaccess file that will get everything to redirect.
right now I have:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.prolectricllc.com/$1 [R=301,L]
And it redirects the main url. BUT how do you get the individual links to redirect to the new pages. The new pages are not named the same;
Example:
Original : www.beaconelectricalservice.com/electricianfriendswood.html
New: http://www.prolectricllc.com/electrician_friendswood.html
I have the individual pages indexed by google so in the SERP’s they click the electricianfriendswood.html link and they get a 404
How can I get all pages to redirect?
Please offer specific instructions as I don’t have much experiences with htaccess
Thanks for your help in advance!
MSWD
April 13, 2010, 2:09am
2
I ended up redirecting each page individually to the new page.
It’s working now, but was there an easier way to accomplish this?
dklynn
April 13, 2010, 5:11am
3
Kathy,
MSWD:
Can anyone help me? We have moved from beaconelectricalservice.com to prolectricllc.com . I want to write a 301 redirect in my htaccess file that will get everything to redirect.
[indent]Did you try
Redirect 301 / http://www.proectricllc.com/
That should do the trick for you!
UNLESS both domains are colocated in which case, use mod_rewrite:
RewriteCond %{HTTP_HOST} beaconelectricalservice\\.com [NC]
RewriteRule .? http://www.prolectricllc.com%{REQUEST_URI} [R=301,L]
# note, %{REQUEST_URI} is already available - no need to fetch it again with (.*)
[/indent]
right now I have:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.prolectricllc.com/$1 [R=301,L]
And it redirects the main url. BUT how do you get the individual links to redirect to the new pages. The new pages are not named the same;
Example:
Original : www.beaconelectricalservice.com/electricianfriendswood.html
New: http://www.prolectricllc.com/electrician_friendswood.html
I have the individual pages indexed by google so in the SERP’s they click the electricianfriendswood.html link and they get a 404
How can I get all pages to redirect?
Please offer specific instructions as I don’t have much experiences with htaccess
Thanks for your help in advance!
Either of the above code samples will do just that for you.
Regards,
DK
system
April 13, 2010, 5:18am
4
it doesnt work in my end.
I ended up redirecting each page individually to the new page.
It’s working now, but was there an easier way to accomplish this?
Since one old page goes to some otherly-named new page, would a rewrite map be of use here?
dklynn
April 14, 2010, 2:38am
6
cal,
First, welcome to SitePoint’s Apache forum.
Second, was that a question?
S-p,
I believe the page names remained the same, just the domain changed. With no response back from the OP, I’m guessing that the problem is solved.
BTW, use of a RewriteMap requires access to the httpd.conf so this is not available to most people (certainly not to those who don’t know to ask about it). That’s for good reason: You can take down the entire server if the script is not properly written!
Regards,
DK
Ah. I asked because link1 in the OP is
electricianfriendswood.html
and the second was
electrician_friendswood.html
as well as new domain name.
Besides rewrite map, and besides manually redirecting each file that got a new name, is there… some other way?
I dunno if this would work, but on Unix you can take a file and make it a link to another file. Could something like that be done?
ln electricianfriendswood.html electrician_friendswood.html
?
dklynn
April 14, 2010, 7:19am
8
Sp,
Good catch! I didn’t see that (either)! No, when someone does NOT plan changes like that, it can (and generally does) end up in a disaster).
Yes, I suppose that symbolic links would work but they are a lot of work in themselves, aren’t they? IMHO, do the same work as for a RewriteMap and put it in a PHP script which can read the “map” in a database and perform a header(‘location:’) redirection - but ONLY if you fail to maintain the same filenames!
Regards,
DK