Solved

How do I set up an htaccess redirect to Google Books

Posted on 2010-09-23
7
532 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
  • 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you have a multi-homed DNS setup in windows, you can have issues with connectivity to the server that hosts the DNS services (or even member servers of your domain if this same DNS server is a DC). This is because windows registers all of its IPs…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now