Solved

How do I set up an htaccess redirect to Google Books

Posted on 2010-09-23
7
546 Views
Last Modified: 2012-05-10
I'd like to set up an automated link shortener for Google Books that uses the GB id and redirects off a short domain (the below is a test domain), so that, for example:

http://gbook.comze.com/Im4JAAAAQAAJ

redirects to

http://www.google.com/books?id=Im4JAAAAQAAJ

Attached is my htaccess. It's not working. What am I doing wrong?

Thanks,

Nathan
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^gbook.comze.com?$ [nc]
rewriterule ^(.*)$ http://http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0
Comment
Question by:nbierm65
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 26

Expert Comment

by:jar3817
ID: 33744961
Try adding "RewriteBase /" in between lines 2 and 3.

I'm assuming this file is named correctly (.htaccess) with the dot in front? And the file is located in the top of your document root? Is this your own server or hosted somewhere? Do you have the "AllowOverride AuthConfig" option set for your document root directory?
0
 

Author Comment

by:nbierm65
ID: 33745185
That didn't do it. It's named correctly (with the dot in front and htaccess as the file extension), in the top root. I added 'AllowOverride AuthConfig.' It's on a free server elsewhere (from 000webhost.com, which I use for live testing). Maybe it's a restriction of that host; I can try a different one...
AllowOverride AuthConfig

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^gbook.comze.com?$ [nc]
rewriterule ^(.*)$ http://http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0
 

Author Comment

by:nbierm65
ID: 33745217
The strange thing to me is I have another auto-shortener set up and working on the same host (different domains), with this code. It's WordPress, which might mean something. But take a look:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^cicw.ws?$ [nc]
rewriterule ^(.*)$ http://www.worshipsymposium.org/archive/?p=$1 [r=301,nc]

# force no-www
RewriteCond %{HTTP_HOST} !^cicw.ws$ [NC]
RewriteRule ^(.*)$ http://cicw.ws/$1 [L,R=301]

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:jar3817
ID: 33745241
The allowoveride is what tells apache to use the .htaccess file, so that goes in the main config, not in the htaccess itself. If it's a hosted account, I'm sure htaccess is setup on it. Perhaps this is something you have to enable on the domain? Did you check their control panel to see if there is such an option? Do you have access to any error logs (usually through their control panel), it might shed some light on the problem.
0
 

Author Comment

by:nbierm65
ID: 33745258
OK I'll check, thanks. Again, the weird thing (re my comment above) is that it's working on a different site at this same host without any extra configuration. But I'll see if there's something I can tweak..
0
 

Author Comment

by:nbierm65
ID: 33783911
OK, I'm wondering if the issue is that the Google Books link is dynamic, ending with '?id= ' -- should I do something like this? (via bit.ly/dqO3Jm)



RewriteEngine on 
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]

Open in new window

0
 

Accepted Solution

by:
nbierm65 earned 0 total points
ID: 33788868
ah, it was just a double 'http://' in the code; no one caught it! Attached is the working code.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com?$ [nc]
rewriterule ^(.*)$ http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
I will assume you are running a non-server version of some sort of Windows throughout this article. There are many flavors of Windows since Windows Server 2000 - 2008, XP Home & Pro, Vista Home & Pro, and Windows 7 Starter, Home, Pro, Ultimate, etc.…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question