Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

How do I set up an htaccess redirect to Google Books

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
nbierm65
Asked:
nbierm65
  • 5
  • 2
1 Solution
 
jar3817Commented:
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
 
nbierm65Author Commented:
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
 
nbierm65Author Commented:
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
Independent Software Vendors: 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!

 
jar3817Commented:
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
 
nbierm65Author Commented:
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
 
nbierm65Author Commented:
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
 
nbierm65Author Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now